def watch_server_pids(server_pids, interval=1, **kwargs):
 status = {}
 start = time.time()
 end = (start + interval)
 server_pids = dict(server_pids)
 while True:
  for (server, pids) in server_pids.items():
   for pid in pids:
    try:
     os.waitpid(pid, os.WNOHANG)
    except OSError as e:
     if (e.errno not in (errno.ECHILD, errno.ESRCH)):
      raise
   status[server] = server.get_running_pids(**kwargs)
   for pid in pids:
    if (pid not in status[server]):
     (yield (server, pid))
   server_pids[server] = status[server]
  if (not [p for (server, pids) in status.items() for p in pids]):
   break
  if (time.time() > end):
   break
  else:
   time.sleep(0.1)

def watch_server_pids ( server_pids , interval = 1 , ** kwargs ) : status = { } start = time . time ( ) end = ( start + interval ) server_pids = dict ( server_pids ) while True : for ( server , pids ) in server_pids . items ( ) : for pid in pids : try : os . waitpid ( pid , os . WNOHANG ) except OSError as e : if ( e . errno not in ( errno . ECHILD , errno . ESRCH ) ) : raise status [ server ] = server . get_running_pids ( ** kwargs ) for pid in pids : if ( pid not in status [ server ] ) : ( yield ( server , pid ) ) server_pids [ server ] = status [ server ] if ( not [ p for ( server , pids ) in status . items ( ) for p in pids ] ) : break if ( time . time ( ) > end ) : break else : time . sleep ( 0.1 )
monitor a collection of server pids yielding back those pids that arent responding to signals .