Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
import time | ||
import subprocess | ||
|
||
cpulimit_procs = {} | ||
worker_cpu_limit = int(os.environ.get("TAPIRIIK_WORKER_CPU_LIMIT", 4)) | ||
|
||
while True: | ||
active_pids = [pid for pid in os.listdir('/proc') if pid.isdigit()] # Sorry, operating systems without procfs | ||
for pid in active_pids: | ||
try: | ||
proc_cmd = open("/proc/%s/cmdline" % pid, "r").read() | ||
except IOError: | ||
continue | ||
else: | ||
if "sync_worker.py" in proc_cmd: | ||
if pid not in cpulimit_procs or cpulimit_procs[pid].poll(): | ||
cpulimit_procs[pid] = subprocess.Popen(["cpulimit", "-l", str(worker_cpu_limit), "-p", pid]) | ||
|
||
for k in list(cpulimit_procs.keys()): | ||
if cpulimit_procs[k].poll(): | ||
cpulimit_procs[k].wait() | ||
del cpulimit_procs[k] | ||
|
||
time.sleep(1) |