# Inhibit suspend (prevent computer sleep) while rendering

Blender, at least on Ubuntu, doesn't prevent the computer from entering sleep while rendering, thus borking the render and combined with a (driver) bug that disables CUDA after suspend, it makes a user's life miserable.

I'm opening this question in order to gather python scripts for various platforms that prevent computer sleep while rendering.

I was tired of having to disable/enable suspend every time so I wrote this addon, which works on Gnome3.

    # © Michael Demetriou 2017

#    This program is free software: you can redistribute it and/or modify
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

bl_info = {
"name": "Inhibit suspend while rendering - for gnome",
"author": "Michael Demetriou",
"version": (1, 0),
"blender": (2, 78, 0),
"description": "Inhibits system suspend while rendering",
"warning": "",
"wiki_url": "",
"tracker_url": "https://gist.github.com/qwazix/290a25576f8c1f80cbc929f5a5d3f27e",
"category": "System"}
###########################################################################

import bpy
import dbus
from bpy.app.handlers import persistent

_session_bus = dbus.SessionBus()
_dbus_screensaver = _session_bus.get_object('org.gnome.SessionManager','/org/gnome/SessionManager')
inhibit = _dbus_screensaver.get_dbus_method('Inhibit','org.gnome.SessionManager')
uninhibit = _dbus_screensaver.get_dbus_method('Uninhibit','org.gnome.SessionManager')

@persistent
def render_pre_handler(dummy):

@persistent
def render_post_handler(dummy):

def register():
bpy.app.handlers.render_pre.append(render_pre_handler)
bpy.app.handlers.render_post.append(render_post_handler)

def unregister():
bpy.app.handlers.render_pre.remove(render_pre_handler)
bpy.app.handlers.render_post.remove(render_post_handler)

if __name__ == "__main__":
register()


You can post similar scripts for your platform with the goal of combining them in a multiplatform addon that could ship with blender.

• macOS doesn't have this problem. It will sleep but still render. It wouldn't need this. – Scott Milner Jan 21 '17 at 16:30
• How is that even possible? Notice that this does not disable the screensaver, just the suspend function. – qwazix Jan 21 '17 at 17:32
• When the sleep comes after the screensaver, it doesn't stop the rendering. I don't know if that holds true for a directly triggered sleep. Also, this might not hold true on a laptop. – Scott Milner Jan 21 '17 at 23:22
• I understand sleep as "low powered state". Rendering can be anything but low power, esp. on GPU, that's why my surprise. I will try it on a macbook though and report. – qwazix Jan 22 '17 at 9:17