Worker: prevent machine from going to sleep #99441

Open
opened 2022-07-04 18:03:25 +02:00 by Sybren A. Stüvel · 3 comments

Workers should prevent the machine they're running on from going to sleep, otherwise they'll time out.

Workers should prevent the machine they're running on from going to sleep, otherwise they'll time out.
Author
Owner

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Author
Owner

Added subscriber: @dr.sybren

Added subscriber: @dr.sybren
Sybren A. Stüvel added
Type
To Do
and removed
Type
Report
labels 2023-02-17 11:12:45 +01:00
Sybren A. Stüvel added
Priority
Low
and removed
Priority
Normal
labels 2024-05-06 10:42:52 +02:00
Contributor

Here is some research of my findings to fix this issue:

  • On Windows it is possible to call SetThreadExecutionState on a regular interval with the ES_SYSTEM_REQUIRED value to prevent sleep.

  • For MacOS, the Technical Q&A QA1340 under Listing 2, shows how to use I/O Kit to prevent sleep. For usage within Go, MacDriver could work, otherwise cgo can be used to interact with I/O Kit natively.

  • With Linux, systemd-inhibit can be used to acquire a sleep lock while the program is running.
    exec.Command("/bin/bash", "systemd-inhibit program").

Alternatively, commands like Powercfg on Windows, can disable/enable sleep without elevated permissions, there might be similar ones for the other two platforms.

Here is some research of my findings to fix this issue: - On Windows it is [possible](https://stackoverflow.com/a/45615169) to call [SetThreadExecutionState](https://msdn.microsoft.com/en-us/library/windows/desktop/aa373208(v=vs.85).aspx) on a regular interval with the `ES_SYSTEM_REQUIRED` value to prevent sleep. - For MacOS, the [Technical Q&A QA1340](https://developer.apple.com/library/archive/qa/qa1340/_index.html) under Listing 2, shows how to use [I/O Kit](https://developer.apple.com/library/archive/documentation/DeviceDrivers/Conceptual/IOKitFundamentals/Features/Features.html) to prevent sleep. For usage within Go, [MacDriver](https://github.com/progrium/macdriver) could work, otherwise [cgo](https://go.dev/blog/cgo) can be used to interact with I/O Kit [natively](https://gist.github.com/nicolai86/fd720c9a660188fe29d7ac7a810f96f3). - With Linux, [systemd-inhibit](https://www.linux.org/docs/man1/systemd-inhibit.html) can be used to acquire a sleep lock while the program is running. `exec.Command("/bin/bash", "systemd-inhibit program")`. Alternatively, commands like [Powercfg](https://learn.microsoft.com/en-us/windows-hardware/design/device-experiences/powercfg-command-line-options) on Windows, can [disable/enable](https://superuser.com/a/90418) sleep without elevated permissions, there might be similar ones for the other two platforms.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: studio/flamenco#99441
No description provided.