tests/killdaemons.py
branchstable
changeset 1123 17bcbb020dda
child 1124 6a5b8503058d
equal deleted inserted replaced
1121:f4dcce73f362 1123:17bcbb020dda
       
     1 #!/usr/bin/env python
       
     2 
       
     3 import os, sys, time, errno, signal
       
     4 
       
     5 # Kill off any leftover daemon processes
       
     6 try:
       
     7     fp = file(os.environ['DAEMON_PIDS'])
       
     8     for line in fp:
       
     9         try:
       
    10             pid = int(line)
       
    11         except ValueError:
       
    12             continue
       
    13         try:
       
    14             os.kill(pid, 0)
       
    15             os.kill(pid, signal.SIGTERM)
       
    16             for i in range(10):
       
    17                 time.sleep(0.05)
       
    18                 os.kill(pid, 0)
       
    19             os.kill(pid, signal.SIGKILL)
       
    20         except OSError, err:
       
    21             if err.errno != errno.ESRCH:
       
    22                 raise
       
    23     fp.close()
       
    24 except IOError:
       
    25     pass