From 5ab7b507be89466b6eb0e1514bb2ff78a27222c9 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 25 Jul 2015 16:58:11 -0700 Subject: [PATCH] Add wrapper scripts (start-cpulimit.sh, kill.sh) to assist running PyLink under cpulimit Again, we're trying to prevent the software from frying people's CPUs... --- kill.sh | 6 ++++++ start-cpulimit.sh | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100755 kill.sh create mode 100755 start-cpulimit.sh diff --git a/kill.sh b/kill.sh new file mode 100755 index 0000000..ad46b13 --- /dev/null +++ b/kill.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +# Script to kill PyLink quickly when running under CPUlimit, since +# it will daemonize after threads are spawned and Ctrl-C won't work. + +kill $(cat pylink.pid) +echo 'Killed. Press Ctrl-C in the PyLink window to exit.' diff --git a/start-cpulimit.sh b/start-cpulimit.sh new file mode 100755 index 0000000..89536ab --- /dev/null +++ b/start-cpulimit.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Shell script to start PyLink under CPUlimit, killing it if it starts abusing the CPU. + +# Set this to whatever you want. cpulimit --help +LIMIT=50 + +# Change to the PyLink root directory. +WRAPPER_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +cd "$WRAPPER_DIR" + +if [[ ! -z "$(which cpulimit)" ]]; then + # -k kills the PyLink daemon if it goes over $LIMIT + # -z makes cpulimit exit when PyLink dies. + cpulimit -l $LIMIT -z -k ./main.py + echo "PyLink has been started (daemonized) under cpulimit, and will automatically be killed if it goes over the CPU limit of ${LIMIT}%." + echo "To kill the process manually, run ./kill.sh" +else + echo 'cpulimit not found in $PATH! Aborting.' +fi