python - Python 阻止屏幕保护程序
问题描述
我需要运行几个小时的代码,并且我正在使用的计算机具有(强制且不可更改的)屏幕保护程序策略。(它会在 10 分钟后锁定)。我能做些什么来防止它?是否有任何代码行可以防止这种情况发生?
解决方案
这对我有用。我会把它留在这里,以便人们使用它。
import ctypes
ctypes.windll.kernel32.SetThreadExecutionState(0x80000002) #this will prevent the screen saver or sleep.
## your code and operations
ctypes.windll.kernel32.SetThreadExecutionState(0x80000000) #set the setting back to normal
推荐阅读
- java - 忽略依赖项中的 Javadoc 错误
- android - 任何人都可以解释错误和/或提供上传的 logcat ss 的一些解决方案吗?
- javascript - Firefox 将 URI 转换为 URL:如何强制它显示 URI
- r - 查找与两种模式中的任何一种匹配的名称
- python - 使用 BeautifulSoup 抓取 CSS 类中的特定元素
- php - 您可以提供哪些详细信息来帮助我了解如何执行 AJAX 以将数据传递到 Datatable 列
- google-cloud-platform - 将数据流式传输到 BQ - 服务帐户所需的理想最低权限
- antd - Ant Design 中的选项卡式表单不可能
- reactjs - 如何使用 ClassName 导入元素 react-js 的样式
- ghostscript - Ubuntu 20.04 上的 ttf2ufm_x2gs