Skip to content

Instantly share code, notes, and snippets.

@sbp
Forked from anonymous/cpulimit.py
Created December 17, 2011 16:17
Show Gist options
  • Save sbp/1490626 to your computer and use it in GitHub Desktop.
Save sbp/1490626 to your computer and use it in GitHub Desktop.
reduce the cpu time of a process by pausing and resuming it repeatedly
#!/usr/bin/env python
import time, os, sys, signal
sleeptime = waketime = 0.01
def send(signal, pids):
for pid in pids:
os.kill(pid, signal)
pids = map(int, sys.argv[1:])
while 1:
send(signal.SIGSTOP, pids)
try: time.sleep(sleeptime)
except KeyboardInterrupt, e:
send(signal.SIGCONT, pids)
raise e
send(signal.SIGCONT, pids)
time.sleep(waketime)
@sbp
Copy link
Author

sbp commented Dec 17, 2011

Forked from Gist 1482811. Adds functionality to make sure the script only exits after a SIGCONT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment