mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 16:58:12 +00:00
More worker cleanups and improvements
This commit is contained in:
@@ -68,9 +68,9 @@ class BaseRenderWorker(object):
|
||||
self.maximum_attempts = 1
|
||||
|
||||
# Threads and processes
|
||||
self.thread = threading.Thread(target=self.run, args=())
|
||||
self.thread.daemon = True
|
||||
self.process = None
|
||||
self.__thread = threading.Thread(target=self.run, args=())
|
||||
self.__thread.daemon = True
|
||||
self.__process = None
|
||||
self.is_finished = False
|
||||
self.last_output = None
|
||||
|
||||
@@ -112,7 +112,7 @@ class BaseRenderWorker(object):
|
||||
|
||||
self.status = RenderStatus.RUNNING
|
||||
logger.info('Starting {0} {1} Render for {2}'.format(self.renderer, self.version(), self.input_path))
|
||||
self.thread.start()
|
||||
self.__thread.start()
|
||||
|
||||
def run(self):
|
||||
|
||||
@@ -135,8 +135,8 @@ class BaseRenderWorker(object):
|
||||
# Start process and get updates
|
||||
subprocess_cmds = self._generate_subprocess()
|
||||
logger.debug("Renderer commands generated - {}".format(" ".join(subprocess_cmds)))
|
||||
self.process = subprocess.Popen(subprocess_cmds, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||
universal_newlines=False)
|
||||
self.__process = subprocess.Popen(subprocess_cmds, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||
universal_newlines=False)
|
||||
self.start_time = datetime.now()
|
||||
|
||||
with open(self.log_path, "a") as f:
|
||||
@@ -144,7 +144,7 @@ class BaseRenderWorker(object):
|
||||
f.write("{3} - Starting {0} {1} Render for {2}\n".format(self.renderer, self.version(), self.input_path,
|
||||
self.start_time.isoformat()))
|
||||
f.write(f"Running command: {' '.join(subprocess_cmds)}\n")
|
||||
for c in io.TextIOWrapper(self.process.stdout, encoding="utf-8"): # or another encoding
|
||||
for c in io.TextIOWrapper(self.__process.stdout, encoding="utf-8"): # or another encoding
|
||||
f.write(c)
|
||||
logger.debug(f"{self.renderer}Worker: {c.strip()}")
|
||||
self.last_output = c.strip()
|
||||
@@ -152,7 +152,7 @@ class BaseRenderWorker(object):
|
||||
f.write('\n')
|
||||
|
||||
# Check return codes
|
||||
return_code = self.process.wait()
|
||||
return_code = self.__process.wait()
|
||||
self.end_time = datetime.now()
|
||||
# Return early if job was cancelled
|
||||
if self.status is RenderStatus.CANCELLED:
|
||||
@@ -180,16 +180,16 @@ class BaseRenderWorker(object):
|
||||
self.is_finished = True
|
||||
|
||||
def is_running(self):
|
||||
if self.thread:
|
||||
return self.thread.is_alive()
|
||||
if self.__thread:
|
||||
return self.__thread.is_alive()
|
||||
return False
|
||||
|
||||
def stop(self):
|
||||
if self.process:
|
||||
if self.__process:
|
||||
try:
|
||||
self.status = RenderStatus.CANCELLED
|
||||
self.maximum_attempts = 0
|
||||
process = psutil.Process(self.process.pid)
|
||||
process = psutil.Process(self.__process.pid)
|
||||
for proc in process.children(recursive=True):
|
||||
proc.kill()
|
||||
process.kill()
|
||||
|
||||
Reference in New Issue
Block a user