def _consume_queue(self, terminate_evt):
"""
This is the main thread function that consumes functions that are
inside the _queue object. To use, execute self._queue(fn), where fn
is a function that performs some kind of network IO or otherwise
benefits from threading and is independent.
terminate_evt is automatically passed in on thread creation and
is a common event for this generation of threads. The threads
will terminate when the event is set and the queue burns down.
Returns: void
"""
interface = self._initialize_interface()
while not terminate_evt.is_set():
try:
fn = self._queue.get(block=True, timeout=0.01)
except Queue.Empty:
continue # periodically check if the thread is supposed to die
fn = partial(fn, interface)
try:
self._consume_queue_execution(fn)
except Exception as err:
self._error_queue.put(err)
self._close_interface(interface)
评论列表
文章目录