4

マルチプロセッシング オブジェクト (キュー、辞書など) を複数の gevent スレッドに渡しても安全ですか? 実際には同時に実行されているわけではないので、問題はないと思います。ただし、gevent が特にマルチプロセッシングと互換性があるとは想定されていないことはわかっています。

4

3 に答える 3

1

利点が失われる可能性があります。標準のスレッド化されたキューは、緑のスレッドが遅くなる可能性があるロックを実装します。ありがたいことに、gevent には独自の類似した構成要素がよくあります。gevent.queueをチェックしてください

于 2015-07-11T01:27:06.610 に答える
1

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#L48

Semaphores 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)

于 2019-08-09T13:10:32.813 に答える