栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Windows中一定时间后终止功能

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Windows中一定时间后终止功能

使用模块中的构件

multiprocessing

import multiprocessingimport QueueTIMEOUT = 5def big_loop(bob):    import time    time.sleep(4)    return bob*2def wrapper(queue, bob):    result = big_loop(bob)    queue.put(result)    queue.close()def run_loop_with_timeout():    bob = 21 # Whatever sensible value you need    queue = multiprocessing.Queue(1) # Maximum size is 1    proc = multiprocessing.Process(target=wrapper, args=(queue, bob))    proc.start()    # Wait for TIMEOUT seconds    try:        result = queue.get(True, TIMEOUT)    except Queue.Empty:        # Deal with lack of data somehow        result = None    finally:        proc.terminate()    # Process data here, not in try block above, otherwise your process keeps running    print resultif __name__ == "__main__":    run_loop_with_timeout()

您也可以使用

Pipe
/
Connection
对来完成此操作,但是我对他们的API并不熟悉。更改睡眠时间或
TIMEOUT
检查两种情况的行为。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/645244.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号