Skip to content

Instantly share code, notes, and snippets.

@wathiede
Created September 10, 2013 17:59
Show Gist options
  • Save wathiede/6513100 to your computer and use it in GitHub Desktop.
Save wathiede/6513100 to your computer and use it in GitHub Desktop.
Hacky, but effective. I leave this running as the same user running the buildbot. Requires: https://code.google.com/p/psutil/
"""Kill old camputs. Helper for buildbot."""
import getpass
import logging
import signal
import sys
import time
import psutil
__author__ = "Bill Thiede"
__copyright__ = "Copyright 2013"
__email__ = "python@xinu.tv"
TOO_OLD_SECS = 300
CYCLE_SECS = 60
def main(args):
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
logging.info('Started')
while True:
me = getpass.getuser()
camputs = [p for p in psutil.process_iter()
if p.username==me and p.name=='camput']
if camputs:
logging.debug('Found %d camput(s)', len(camputs))
now = time.time()
for c in camputs:
d = now - c.create_time
if d > TOO_OLD_SECS:
logging.info('Killing %s', c)
c.send_signal(signal.SIGQUIT)
else:
logging.info('Waiting to kill %s, only %f seconds old', p, d)
time.sleep(CYCLE_SECS)
if __name__ == '__main__':
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment