Skip to content

Commit

Permalink
improves: fix MultiProcess args and kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsneto committed Nov 11, 2023
1 parent 1fe31b1 commit 24968a1
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions cereja/concurrently/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, max_threads: int):
self._terminate = False
self._results = []

def execute(self, function, values, args, kwargs) -> list:
def execute(self, function, values, *args, **kwargs) -> list:
"""
Execute the given function using multiple threads on the provided values.
Expand All @@ -47,7 +47,7 @@ def execute(self, function, values, args, kwargs) -> list:
print("Terminating due to an exception in one of the threads. Returning processed data...")
break
thread = threading.Thread(target=self._execute_function_thread, name=f'Thread-{indx}',
args=(function, value, indx, args[indx] if args else args, kwargs[indx] if kwargs else kwargs))
args=(function, value, indx, args, kwargs))
with self._lock:
self._active_threads += 1
thread.start()
Expand Down Expand Up @@ -80,11 +80,7 @@ def _execute_function_thread(self, function, value, indx, args, kwargs):
"""
try:
if not self._terminate:
if args or kwargs:
self._results.append((indx, function(value, *args, **kwargs)))
else:
self._results.append((indx, function(value)))

self._results.append((indx, function(value, *args, **kwargs)))
except Exception as e:
print(f"Error encountered in thread: {e}")
self._terminate = True
Expand Down

0 comments on commit 24968a1

Please sign in to comment.