本文介绍了阻止OS X使用Python进入睡眠状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以防止运行OS X的计算机从Python脚本中进入睡眠状态?
Is there a way to prevent a computer running OS X from going to sleep from within a Python script?
推荐答案
您可以使用内置的 caffeinate 命令.
You can use the built-in caffeinate command.
subprocess.Popen('caffeinate')
这是我的用法:
import sys
import subprocess
if 'darwin' in sys.platform:
print('Running \'caffeinate\' on MacOSX to prevent the system from sleeping')
subprocess.Popen('caffeinate')
这篇关于阻止OS X使用Python进入睡眠状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!