未知
项目描述
gevent-helpers 包含了一组在开发中使用 gevent 时有帮助的实用工具。
与 gevent==1.0rc3 兼容。
fork()
直到该问题得到修复,这是对 gevent问题154 的解决方案。
BlockingDetector(timeout=1, raise_exc=AlarmInterrupt, aggressive=True)
使用操作系统信号检测阻塞线程。
timeout=1 是在认为线程阻塞之前等待的秒数(注意:如果 signal.setitimer 或 itimer 包可用,这可以是一个实数;否则它将被四舍五入到最接近的整数)。
raise_exc=AlarmInterrupt 控制在阻塞线程中将引发哪个异常。如果 raise_exc 为假,则不会引发异常(将始终发出包括堆栈跟踪的 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
项目详情
关闭
gevent-helpers-0.1.1.tar.gz 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 4870b19928b51b39952b40e6c696f7f97a45ee150edf407501958479b584de5b |
|
MD5 | 93291d7f5f585970e015d9989c385e2d |
|
BLAKE2b-256 | 3fefaa2ffbd3dc58d88a2a7df24b62c9162d06650c3ca63365865345a3df2b2f |