未知
gevent-helpers的Python项目详细描述
gevent-helpers包含在 使用gevent开发
与gevent==1.0rc3兼容
fork()
在问题解决之前,gevent issue 154的解决方法。
阻塞检测器(超时=1,raise_exc=AlarmInterrupt,aggressive=True)
使用操作系统信号检测阻塞线程。
timeout=1是在考虑 线程被阻塞(注意:如果signal.setitimer或itimer包是 可用,这可以是实数;否则将四舍五入为 最接近的整数)
raise_exc=AlarmInterrupt控制将引发哪个异常 在阻塞线程中。如果raise_exc为假ish,则不会有异常 引发(一条log.warning消息,包括堆栈跟踪,将始终是 发布)。注意:默认值AlarmInterrupt是 BaseException,因此它不会被except Exception:捕获。 将被dirt.runloop捕获例如:
# Don't raise an exception, only log a warning message and stack trace: BlockingDetector(raise_exc=False) # Raise ``MyException()`` and lot a warning message: BlockingDetector(raise_exc=MyException()) # Raise ``MyException("blocking detected after timeout=...")`` and log # a warning message: BlockingDetector(raise_exc=MyException)
aggressive=True确定阻塞检测器是否将重置 一旦被触发,或者是否会等到阻塞 线程在重置之前会屈服。例如,如果aggressive=True, raise_exc=False和timeout=1,将为 每一秒都有一根线阻塞。但是,如果aggressive=False,则仅 在阻塞线程产生之前,将写入一条日志消息,此时 警报将被重置。
注意:BlockingDetector覆盖signal.SIGALRM处理程序和 不尝试保存上一个值。
例如:
>>> def spinblock(): ... while True: ... pass >>> gevent.spawn(BlockingDetector()) >>> gevent.sleep() >>> spinblock() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in spinblock File ".../dirt/misc/gevent_.py", line 167, in alarm_handler raise exc gevent_helpers.AlarmInterrupt: blocking detected after timeout=1