utils.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:ResponseBot 作者: invinst 项目源码 文件源码
def time_limit(seconds):
    '''
    Context manager (with statement) to handle long function calls.
    Needed to test the while loop in Listener

    :param seconds: time before stop
    '''
    def signal_handler(signum, frame):
        raise SignalTimeoutException('{sec} seconds are over!'.format(sec=seconds))

    # Sets a timeout using signal
    signal.signal(signal.SIGALRM, signal_handler)
    signal.alarm(seconds)

    try:
        yield
    finally:
        signal.alarm(0)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号