Are Generators Threadsafe?

后端 未结 6 864
闹比i
闹比i 2020-12-02 09:29

I have a multithreaded program where I create a generator function and then pass it to new threads. I want it to be shared/global in nature so each thread can get the next

6条回答
  •  醉话见心
    2020-12-02 09:39

    It depends on which python implementation you're using. In CPython, the GIL makes all operations on python objects threadsafe, as only one thread can be executing code at any given time.

    http://en.wikipedia.org/wiki/Global_Interpreter_Lock

提交回复
热议问题