Skip to content

Commit

Permalink
! threading limit tryouts
Browse files Browse the repository at this point in the history
  • Loading branch information
ALERTua committed Aug 5, 2024
1 parent 231dbae commit 031c493
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions rozetka/tools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,25 @@ def _worker(*worker_args, **worker_kwargs):

def fncs_map(tuple_of_fncs, *tuple_of_args):
workers = []
outputs = []
for fnc, fnc_args in zip_longest(tuple_of_fncs, tuple_of_args):
if (workers_len := len(workers)) >= constants.THREADS_MAX:
LOG.debug(f"Workers: {workers_len}. Waiting")
for worker_ in workers:
outputs.append(worker_.await_worker())
workers.remove(worker_)

@worker
def _worker(*worker_args):
return fnc(*worker_args)

fnc_args = fnc_args or []
wait_workers_limit()
workers.append(_worker(*fnc_args))
__worker = _worker(*fnc_args)
workers.append(__worker)

outputs = []
for worker_ in workers:
worker_.wait()
outputs.append(worker_.ret)
outputs.append(worker_.await_worker())
workers.remove(worker_)
return outputs


Expand Down

0 comments on commit 031c493

Please sign in to comment.