Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _kill_workers(self):
"""Kill the workers"""
for w in self.W['worker_id']:
self.wcomms[w-1].send(STOP_TAG, MAN_SIGNAL_FINISH)
def run(self):
"Run the main worker loop."
try:
logger.info("Worker {} initiated on node {}".
format(self.workerID, socket.gethostname()))
for worker_iter in count(start=1):
logger.debug("Iteration {}".format(worker_iter))
mtag, Work = self.comm.recv()
if mtag == STOP_TAG:
break
response = self._handle(Work)
if response is None:
break
self.comm.send(0, response)
except Exception as e:
self.comm.send(0, WorkerErrMsg(str(e), format_exc()))
else:
self.comm.kill_pending()
finally:
if self.sim_specs.get('clean_jobs') and self.loc_stack is not None:
self.loc_stack.clean_locs()
def manager_poll(self, comm):
""" Polls for a manager signal
The executor manager_signal attribute will be updated.
"""
# Check for messages; disregard anything but a stop signal
if not comm.mail_flag():
return
mtag, man_signal = comm.recv()
if mtag != STOP_TAG:
return
# Process the signal and push back on comm (for now)
logger.info('Manager probe hit true')
if man_signal == MAN_SIGNAL_FINISH:
self.manager_signal = 'finish'
elif man_signal == MAN_SIGNAL_KILL:
self.manager_signal = 'kill'
else:
logger.warning("Received unrecognized manager signal {} - "
"ignoring".format(man_signal))
comm.push_to_buffer(mtag, man_signal)
else:
out = calc(calc_in, Work['persis_info'], Work['libE_info'])
logger.debug("Return from calc call")
assert isinstance(out, tuple), \
"Calculation output must be a tuple."
assert len(out) >= 2, \
"Calculation output must be at least two elements."
calc_status = out[2] if len(out) >= 3 else UNSET_TAG
# Check for buffered receive
if self.comm.recv_buffer:
tag, message = self.comm.recv()
if tag in [STOP_TAG, PERSIS_STOP]:
if message is MAN_SIGNAL_FINISH:
calc_status = MAN_SIGNAL_FINISH
return out[0], out[1], calc_status
except Exception:
logger.debug("Re-raising exception from calc")
calc_status = CALC_EXCEPTION
raise
finally:
# This was meant to be handled by calc_stats module.
if task_timing and Executor.executor.list_of_tasks:
# Initially supporting one per calc. One line output.
task = Executor.executor.list_of_tasks[-1]
calc_msg = "Calc {:5d}: {} {} {} Status: {}".\
format(calc_id,
calc_type_strings[calc_type],