我有一个在Windows 8.1上运行的后台运行的Python 2.7进程。
有没有办法正常结束这个过程,并closures或注销清理?
使用ShellExecuteEx永久设置pathvariables
在Windows主机上访问Docker容器URL
pyproj与Python 2.7.9在win7 64上给出“无法findvcvarsall.bat”
使用terraform,Chef或Powershell以编程方式设置EBS卷的Windows驱动器盘符
Windows 10 UWP – C#:如何检查networkingtypes(EDGE / 3G / LTE),不仅是蜂窝与WLAN?
尝试使用win32api.GenerateConsoleCtrlEvent。
我解决了这个多处理python程序在这里: 优雅地终止子Python进程在Windows上,所以最后子句运行
我使用subprocess.Popen测试了这个解决方案,它也可以。
import time import win32api import win32con from multiprocessing import Process def foo(): try: while True: print("Child process still working...") time.sleep(1) except KeyboardInterrupt: print "Child process: caught ctrl-c" if __name__ == "__main__": p = Process(target=foo) p.start() time.sleep(2) print "sending ctrl c..." try: win32api.GenerateConsoleCtrlEvent(win32con.CTRL_C_EVENT,0) while p.is_alive(): print("Child process is still alive.") time.sleep(1) except KeyboardInterrupt: print "Main process: caught ctrl-c"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。