Option to prevent sleep if task is running #20898

Closed
opened 2026-01-31 07:27:09 +00:00 by claunia · 9 comments
Owner

Originally created by @Sergio0694 on GitHub (Nov 25, 2023).

Description of the new feature/enhancement

On my machine, I have set the sleep time to 15 minutes. Sometimes (eg. when running long builds) I would just step away from it and let it work, but then come back with it being on standby and with the work just paused, which is pretty annoying. It would be nice if Terminal had an option to make it automatically prevent the machine going to sleep if there's some operation running in any tabs. This is pretty common for other applications/websites as well (eg. if you have Spotify playing music in Edge, your computer won't go to sleep).

Note

Tried searching for a similar issue and couldn't find one, so hopefully this is not a duplicate.

Proposed technical implementation details

PowerToys is already doing this in their "awake" feature, we could probably just do the same here?
Ie. SetThreadExecutionState?

Originally created by @Sergio0694 on GitHub (Nov 25, 2023). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> # Description of the new feature/enhancement On my machine, I have set the sleep time to 15 minutes. Sometimes (eg. when running long builds) I would just step away from it and let it work, but then come back with it being on standby and with the work just paused, which is pretty annoying. It would be nice if Terminal had an option to make it automatically prevent the machine going to sleep if there's some operation running in any tabs. This is pretty common for other applications/websites as well (eg. if you have Spotify playing music in Edge, your computer won't go to sleep). > [!NOTE] > Tried searching for a similar issue and couldn't find one, so hopefully this is not a duplicate. # Proposed technical implementation details PowerToys is already doing this in their "awake" feature, we could probably just do the same here? Ie. [`SetThreadExecutionState`](https://github.com/microsoft/PowerToys/blob/a090558aad7065b2cfb2892922048e74cb5f546d/src/modules/awake/Awake/Core/Manager.cs#L85)?
claunia added the Issue-FeatureNeeds-TriageResolution-ExternalNeeds-Tag-Fix labels 2026-01-31 07:27:10 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Nov 29, 2023):

I... don't hate this. But knowing when to do this would be tricky. We wouldn't necessarily want to always prevent sleep if the Terminal is running - we'd probably want to only do that if there's a child process running. That of course gets into weird edge cases - just running ssh from a shell (or heck, just cmd.exe from PowerShell) would then satisfy the heuristic here and would keep the PC alive.

Terminal doesn't currently track the tree of processes. We'll need to do that for #6549 though

@zadjii-msft commented on GitHub (Nov 29, 2023): I... don't hate this. But knowing when to do this would be tricky. We wouldn't necessarily want to _always_ prevent sleep if the Terminal is running - we'd probably want to only do that if there's a child process running. That of course gets into weird edge cases - just running `ssh` from a shell (or heck, just cmd.exe from PowerShell) would then satisfy the heuristic here and would keep the PC alive. Terminal doesn't currently track the tree of processes. We'll need to do that for #6549 though
Author
Owner

@Sergio0694 commented on GitHub (Nov 29, 2023):

To give a real world use case scenario, I hit this when building https://github.com/microsoft/CsWinRT locally, which takes like half an hour. Started ./build.cmd, stepped away, came back after an hour and the PC had just gone to sleep after 10 minutes 🤦‍♂️

@Sergio0694 commented on GitHub (Nov 29, 2023): To give a real world use case scenario, I hit this when building https://github.com/microsoft/CsWinRT locally, which takes like half an hour. Started `./build.cmd`, stepped away, came back after an hour and the PC had just gone to sleep after 10 minutes 🤦‍♂️
Author
Owner

@DHowett commented on GitHub (Nov 29, 2023):

This may be more suitable as a tool outside of Terminal, FWIW. I'm imagining something like macOS' caffeinate. You can caffeinate, and it will keep the machine awake until you press Ctrl+C, or you can caffeinate foo and it will keep the machine awake until foo exits.

@DHowett commented on GitHub (Nov 29, 2023): This may be more suitable as a tool outside of Terminal, FWIW. I'm imagining something like macOS' `caffeinate`. You can `caffeinate`, and it will keep the machine awake until you press <kbd>Ctrl+C</kbd>, or you can `caffeinate foo` and it will keep the machine awake until `foo` exits.
Author
Owner

@zadjii-msft commented on GitHub (Nov 29, 2023):

that's actually really clever

@zadjii-msft commented on GitHub (Nov 29, 2023): that's actually really clever
Author
Owner

@Sergio0694 commented on GitHub (Nov 29, 2023):

Would it perhaps make sense to have it just built-in into Terminal, so you can opt-in on a per-command basis?

@Sergio0694 commented on GitHub (Nov 29, 2023): Would it perhaps make sense to have it just built-in into Terminal, so you can opt-in on a per-command basis?
Author
Owner

@zadjii-msft commented on GitHub (Dec 5, 2023):

have it just built-in into Terminal ... ?

Eh, honestly, in the name of trying to keep things as minimal as possible, probably not. However, there is PowerToys.Awake, but I cannot for the life of me figure out how to get the CLI to work

@crutkas help me out

@zadjii-msft commented on GitHub (Dec 5, 2023): > have it just built-in into Terminal ... ? Eh, honestly, in the name of trying to keep things as minimal as possible, probably not. However, there is [PowerToys.Awake](https://learn.microsoft.com/en-us/windows/powertoys/awake#command-line-interface-cli), but I cannot for the life of me figure out how to get the CLI to work @crutkas help me out
Author
Owner

@crutkas commented on GitHub (Dec 7, 2023):

as of now, you'd need to turn off awake PowerToys can do it all via CLI but you'll want to turn it off inside PowerToys. We're working on improving this so the two can work side by side.

I grabbed the PID for Notepad in this example

PS C:\Users\crutkas> cd C:\Users\crutkas\AppData\Local\PowerToys
PS C:\Users\crutkas\AppData\Local\PowerToys> .\PowerToys.Awake.exe --pid 24384 --display-on true
image

soon as i closed out notepad, screen would turn off.

Good feedback for better documentation and see if we can't do CLI + PT open at same time work.

@crutkas commented on GitHub (Dec 7, 2023): as of now, you'd need to turn off awake PowerToys can do it all via CLI but you'll want to turn it off inside PowerToys. We're working on improving this so the two can work side by side. I grabbed the PID for Notepad in this example PS C:\Users\crutkas> cd C:\Users\crutkas\AppData\Local\PowerToys PS C:\Users\crutkas\AppData\Local\PowerToys> .\PowerToys.Awake.exe --pid 24384 --display-on true ![image](https://github.com/microsoft/terminal/assets/1462282/9ea0a9ee-d2a2-4239-80b1-62e360bc278e) soon as i closed out notepad, screen would turn off. Good feedback for better documentation and see if we can't do CLI + PT open at same time work.
Author
Owner

@crutkas commented on GitHub (Dec 7, 2023):

@zadjii-msft i believe we can close this out as PT would be the team for this

@crutkas commented on GitHub (Dec 7, 2023): @zadjii-msft i believe we can close this out as PT would be the team for this
Author
Owner

@DHowett commented on GitHub (Dec 7, 2023):

Thanks @crutkas!

@Sergio0694, if PowerToys Awake (CLI) doesn't quite fit your needs... we can all work together to make sure something does. 😄

@DHowett commented on GitHub (Dec 7, 2023): Thanks @crutkas! @Sergio0694, if PowerToys Awake (CLI) doesn't quite fit your needs... we can all work together to make sure something _does_. :smile:
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20898