Skip to content

Commit

Permalink
updates from other projects
Browse files Browse the repository at this point in the history
  • Loading branch information
klahnakoski committed Jan 5, 2025
1 parent f9c3cf4 commit 8c75a43
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions mo_threads/pools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from mo_threads.queues import Queue
from mo_threads.threads import Thread
from mo_threads.threads import join_all_threads, PLEASE_STOP, current_thread
from mo_threads.threads import join_all_threads, PLEASE_STOP


class ThreadPool:
Expand All @@ -13,7 +13,7 @@ def __init__(self, num_threads, name=None):

def __enter__(self):
self.workers = [
Thread.run(f"{self.name}-{i}", worker, self)
Thread.run(f"{self.name}-worker-{i}", worker, self)
for i in range(self.num_threads)
]
return self
Expand All @@ -29,15 +29,11 @@ def run(self, name, target, *args, **kwargs):


def worker(pool, please_stop):
this = current_thread()
this_name = this.name
while not please_stop:
thread = pool.queue.pop(till=please_stop)
if thread is PLEASE_STOP:
break
this.threading_thread.name = thread.name
try:
thread.start().join(till=please_stop)
except Exception as cause:
except Exception:
pass
this.threading_thread.name = this_name

0 comments on commit 8c75a43

Please sign in to comment.