首页 > 解决方案 > Python 阻止屏幕保护程序

问题描述

我需要运行几个小时的代码,并且我正在使用的计算机具有(强制且不可更改的)屏幕保护程序策略。(它会在 10 分钟后锁定)。我能做些什么来防止它?是否有任何代码行可以防止这种情况发生?

标签: python

解决方案


这对我有用。我会把它留在这里,以便人们使用它。

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

推荐阅读