def stopWorker(basedir, quiet, signame='TERM'):
 import signal
 os.chdir(basedir)
 try:
  f = open('twistd.pid', 'rt')
 except IOError:
  raise WorkerNotRunning()
 pid = int(f.read().strip())
 signum = getattr(signal, ('SIG' + signame))
 timer = 0
 try:
  os.kill(pid, signum)
 except OSError as e:
  if (e.errno != 3):
   raise
 time.sleep(0.1)
 while (timer < 10):
  try:
   os.kill(pid, 0)
  except OSError:
   if (not quiet):
    print(('worker process %d is dead' % pid))
   return 0
  timer += 1
  time.sleep(1)
 if (not quiet):
  print('never saw process go away')
 return 1

def stopWorker ( basedir , quiet , signame = 'TERM' ) : import signal os . chdir ( basedir ) try : f = open ( 'twistd.pid' , 'rt' ) except IOError : raise WorkerNotRunning ( ) pid = int ( f . read ( ) . strip ( ) ) signum = getattr ( signal , ( 'SIG' + signame ) ) timer = 0 try : os . kill ( pid , signum ) except OSError as e : if ( e . errno != 3 ) : raise time . sleep ( 0.1 ) while ( timer < 10 ) : try : os . kill ( pid , 0 ) except OSError : if ( not quiet ) : print ( ( 'worker process %d is dead' % pid ) ) return 0 timer += 1 time . sleep ( 1 ) if ( not quiet ) : print ( 'never saw process go away' ) return 1
stop worker process by sending it a signal .