Skip to content

Commit

Permalink
Merge pull request #29 from BrianPugh/remove-lox
Browse files Browse the repository at this point in the history
remove lox dependency for standard thread pool executor
  • Loading branch information
BrianPugh authored Oct 21, 2022
2 parents c0ccc3f + ad5c331 commit dcd2c95
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
19 changes: 11 additions & 8 deletions belay/device.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ast
import concurrent.futures
import importlib.resources as pkg_resources
import linecache
import secrets
Expand All @@ -13,7 +14,6 @@
from pathlib import Path
from typing import Callable, Dict, Generator, List, Optional, Set, TextIO, Tuple, Union

import lox
from pathspec import PathSpec
from serial import SerialException

Expand Down Expand Up @@ -387,7 +387,6 @@ def _preprocess_src_file(
return src_file


@lox.thread(8)
def _preprocess_src_file_hash(*args, **kwargs):
src_file = _preprocess_src_file(*args, **kwargs)
src_hash = _local_hash_file(src_file)
Expand Down Expand Up @@ -650,21 +649,25 @@ def sync(
progress_update(description="Creating remote directories...")
self(f"__belay_mkdirs({repr(dst_dirs)})")

with tempfile.TemporaryDirectory() as tmp_dir:
with tempfile.TemporaryDirectory() as tmp_dir, concurrent.futures.ThreadPoolExecutor(
max_workers=5
) as executor:
tmp_dir = Path(tmp_dir)
for src_file in src_files:
# Pre-process files in another thread while we get remote hashes
_preprocess_src_file_hash.scatter(

def _preprocess_src_file_hash_helper(src_file):
return _preprocess_src_file_hash(
tmp_dir, src_file, minify, mpy_cross_binary
)

src_files_and_hashes = executor.map(
_preprocess_src_file_hash_helper, src_files
)

# Get all remote hashes
if progress_update:
progress_update(description="Fetching remote hashes...")
dst_hashes = self(f"__belay_hfs({repr(dst_files)})")

src_files_and_hashes = _preprocess_src_file_hash.gather()

if len(dst_hashes) != len(dst_files):
raise Exception

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ python = "^3.8"
pyserial = "^3.1"
typer = {extras = ["all"], version = "^0.6"}
pathspec = "*"
lox = "^0.11.0"

[tool.poetry.group.docs.dependencies]
sphinx = "~4.5.0"
Expand Down

0 comments on commit dcd2c95

Please sign in to comment.