跳转到主要内容

未知

项目描述

gevent-helpers 包含了一组在开发中使用 gevent 时有帮助的实用工具。

gevent==1.0rc3 兼容。

fork()

直到该问题得到修复,这是对 gevent问题154 的解决方案。

BlockingDetector(timeout=1, raise_exc=AlarmInterrupt, aggressive=True)

使用操作系统信号检测阻塞线程。

timeout=1 是在认为线程阻塞之前等待的秒数(注意:如果 signal.setitimeritimer 包可用,这可以是一个实数;否则它将被四舍五入到最接近的整数)。

raise_exc=AlarmInterrupt 控制在阻塞线程中将引发哪个异常。如果 raise_exc 为假,则不会引发异常(将始终发出包括堆栈跟踪的 log.warning 消息)。注意:默认值 AlarmInterruptBaseException 的子类,因此它 不会 被由 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=Trueraise_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 (3.7 kB 查看散列)

上传时间

由以下支持