マルチプロセッシング オブジェクト (キュー、辞書など) を複数の gevent スレッドに渡しても安全ですか? 実際には同時に実行されているわけではないので、問題はないと思います。ただし、gevent が特にマルチプロセッシングと互換性があるとは想定されていないことはわかっています。
3 に答える
利点が失われる可能性があります。標準のスレッド化されたキューは、緑のスレッドが遅くなる可能性があるロックを実装します。ありがたいことに、gevent には独自の類似した構成要素がよくあります。gevent.queueをチェックしてください
Unfortunately, it seems like, at the moment, gevent
is not compatible with objects from multiprocessing
:
It is dangerous. The
mp.Queue
and other mp data structures utilize things like Semaphores internally: https://github.com/python/cpython/blob/master/Lib/multiprocessing/queues.py#L48Semaphores under Linux are not fd-based and would require threaded wrappers to unblock the main loop thread. Generally speaking, if things go south, it's possible to completely block the main thread with a semaphore waiting infinitely for some event to happen.
(Quote from GitHub issues https://github.com/gevent/gevent/issues/1443)