Python函数超时,用装饰器解决, win可以运行

 

 

 

 

https://mp.weixin.qq.com/s/u5VGromE6iJmBBUoNaPFmw

 

pip install func_timeout

 

 

# -*- coding: utf-8 -*-

import time

from func_timeout import func_set_timeout


@func_set_timeout(5)
def task():
    while True:
        print('hello world')
        time.sleep(1)

if __name__ == '__main__':
    task()

 

posted @ 2023-10-26 15:08  AngDH  阅读(40)  评论(0编辑  收藏  举报