Python freezes after computer sleep/hibernate

試著忘記壹切 提交于 2019-12-22 18:20:16

问题


I have a python script that is running in the background with pythonw. If I close my laptop, it goes into sleep mode. and when I open my laptop, my program has little functionality and freezes after a couple of seconds. Is there any way that my script can tell if my computer is going into sleep mode, so that it can lie dormant and restart when I re-open my laptop?


回答1:


You can catch WM_POWERBROADCAST window message with PBT_APMQUERYSUSPEND event inside it. To catch this message inside Python program, you can create new invisible window and make separate thread repeatedly calling GetMessage().

In the worst case you can archieve all these by using ctypes only, but you can also use pywin32, sometimes referred to as win32py.



来源:https://stackoverflow.com/questions/1959669/python-freezes-after-computer-sleep-hibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!