简体   繁体   English

Gevent greenlet冒充父母的例外

[英]Gevent greenlet bubbling up exceptions to the parent

In using gevent, whenever a child greenlet throws an exception, I would like it to bubble up to the parent (and ideally have the parent throw the exception). 在使用gevent时,每当一个子greenlet抛出异常时,我希望它冒泡到父级(理想情况下让父级抛出异常)。 In the documentation for greenlets, it says this is automatically done, but this doesn't appear to be the case in gevent. 在greenlets的文档中,它表示这是自动完成的,但在gevent中似乎并非如此。

How do I bubble up exceptions in gevent? 如何在gevent中冒出异常?

Thanks! 谢谢!

If you link() the child greenlet to the parent greenlet, then LinkedExited will be raised in the parent when the child exits. 如果将子greenlet link()到父greenlet,则子项退出时将在父项中引发LinkedExited At that point you can check the exception property of the child greenlet. 此时,您可以检查子greenlet的exception属性。 It will contain the exception instance raised in the child (if the child finished with an error). 它将包含在子代中引发的异常实例(如果子代完成了错误)。 Now that you have the exception, you could handle it right away in the parent or you could raise it in the parent. 现在您有异常,您可以立即在父级中处理它,或者您可以在父级中提升它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM