def sim_kill(self):
"""
Forcibly kill (i.e. terminate) the current simulation. Practically, this method terminates the process of
the simulation code and sets the simulation status to STOP.
:return: Return 0 if succeed, -1 if failed. If the simulation is not running, then it cannot be killed, causing
the method to do nothing but return 1.
"""
# Find the process by PID
if self.config.has_option('Simulation', 'PID'):
pid = self.config.getint('Simulation', 'PID')
try:
os.kill(pid, signal.SIGKILL)
msg = 'Simulation %s (PID: %d) killed.' % (self.name, pid)
print(msg)
if self.logger is not None:
self.logger.info(msg)
except OSError, err:
msg = '%s: Cannot kill the process: %s\n' % (str(err), self.name)
print(msg)
if self.logger is not None:
self.logger.warning(msg)
return 0
评论列表
文章目录