开发者

Forking Greenlets

开发者 https://www.devze.com 2023-02-13 06:54 出处:网络
Perhaps I\'m missing something obvious (and it is a Friday), but is there a way to do the equivalent of an os.fork() on a开发者_StackOverflow社区 greenlet? I\'m not necessarily looking to fork the pro

Perhaps I'm missing something obvious (and it is a Friday), but is there a way to do the equivalent of an os.fork() on a开发者_StackOverflow社区 greenlet? I'm not necessarily looking to fork the process, I'm looking to take the greenlet and run one set of code, then another, but with independent scopes (as with os.fork()).

Any ideas or should I just get some sleep?


In order to conceptually fork a greenlet, just create another greenlet wrapping your "child function". I also highly recommend gevent, which is built on greenlet. The gevent code has a fork() method, but it forks the Python process and then restarts gevent in the child. I bet that you can implement whatever you are doing in gevent with more readable code than just greenlet.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号