warning(" @SOCKET: Timeout! Request for bead "+str(r["id"])+" has been running for "+str(time.time()-r["start"])+" sec.",verbosity.low)
warning(" @SOCKET: Client "+str(c.peername)+" died or got unresponsive(B). Disconnecting.",verbosity.low)
try:
c.shutdown(socket.SHUT_RDWR)
exceptsocket.error:
e=sys.exc_info()
warning(" @SOCKET: could not shut down cleanly the socket. %s: %s in file '%s' on line %d"%(e[0].__name__,e[1],os.path.basename(e[2].tb_frame.f_code.co_filename),e[2].tb_lineno),verbosity.low)
warning(" @SOCKET: Client "+str(fc.peername)+" is in an unexpected status "+str(fc.status)+" at (1). Will try to keep calm and carry on.",verbosity.low)
continue
formatch_idsin("match","none","free","any"):
forrinpendr[:]:
ifmatch_ids=="match"andnotfc.lastreqisr["id"]:
continue
elifmatch_ids=="none"andnotfc.lastreqisNone:
continue
elifmatch_ids=="free"andfc.locked:
continue
info(" @SOCKET: Assigning [%5s] request id %4s to client with last-id %4s (% 3d/% 3d : %s)"%(match_ids,str(r["id"]),str(fc.lastreq),self.clients.index(fc),len(self.clients),str(fc.peername)),verbosity.high)
whilefc.status&Status.Busy:
fc.poll()
iffc.status&Status.NeedsInit:
fc.initialize(r["id"],r["pars"])
fc.poll()
whilefc.status&Status.Busy:# waits for initialization to finish. hopefully this is fast
fc.poll()
iffc.status&Status.Ready:
fc.sendpos(r["pos"],r["cell"])
r["status"]="Running"
r["start"]=time.time()# sets start time for the request
fc.poll()
self.jobs.append([r,fc])
fc.locked=(fc.lastreqisr["id"])
matched=True
# removes r from the list of pending jobs
pendr=[nrfornrinpendrif(notnrisr)]
break
else:
warning(" @SOCKET: Client "+str(fc.peername)+" is in an unexpected status "+str(fc.status)+" at (2). Will try to keep calm and carry on.",verbosity.low)
ifmatched:
break# doesn't do a second (or third) round if it managed
# to assign the job
def_kill_handler(self,signal,frame):
"""Deals with handling a kill call gracefully.
Prevents any of the threads becoming zombies, by intercepting a
kill signal using the standard python function signal.signal() and
then closing the socket and the spawned threads before closing the main
thread. Called when signals SIG_INT and SIG_TERM are received.
Args:
signal: An integer giving the signal number of the signal received
from the socket.
frame: Current stack frame.
"""
warning(" @SOCKET: Kill signal. Trying to make a clean exit.",verbosity.low)
self.end_thread()
softexit.trigger(" @SOCKET: Kill signal received")
try:
self.__del__()
except:
pass
ifsignalinself._prev_kill:
self._prev_kill[signal](signal,frame)
def_poll_loop(self):
"""The main thread loop.
Runs until either the program finishes or a kill call is sent. Updates
the pool of clients every UPDATEFREQ loops and loops every latency
seconds until _poll_true becomes false.
"""
info(" @SOCKET: Starting the polling thread main loop.",verbosity.low)
self._poll_iter=UPDATEFREQ
whileself._poll_true:
time.sleep(self.latency)
# makes sure to remove the last dead client as soon as possible -- and to get clients if we are dry