擅长:python、mysql、java
<p>我认为您应该看看事件驱动编程(<a href="https://emptypage.jp/notes/pyevent.en.html" rel="nofollow noreferrer">https://emptypage.jp/notes/pyevent.en.html</a>)</p>
<p>并且没有针对完工工人的while循环轮询:</p>
<p>例如:</p>
<pre><code>def create_thread(self, work_finished_method):
t = some_method_to_create_and prepare_a_thread()
t.event_finished += work_finished_method
return t
class MyThread:
name = "SomeNameForTheThread"
event_finished = event.Event(name + " has finished.")
def finished(self):
self.event_finished()
def do_work:
do_something()
finished()
</code></pre>
<p>当在mainhthread中调用<code>work_finished</code>方法时,可以为线程分配新的工作</p>