May need to ditch threads in favor of async
This commit is contained in:
@ -15,7 +15,7 @@ class IrisSystemThread(Thread):
|
||||
##
|
||||
# Run the defined action
|
||||
##
|
||||
async def run(self):
|
||||
def run(self):
|
||||
logger.info("Running system action '"+self.action+"'")
|
||||
|
||||
try:
|
||||
@ -32,31 +32,18 @@ class IrisSystemThread(Thread):
|
||||
self.callback(False, error)
|
||||
return
|
||||
|
||||
# Create subprocess
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
self.path+"/system.sh "+self.action,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
|
||||
# Status
|
||||
print("Started:", command, "(pid = " + str(process.pid) + ")", flush=True)
|
||||
|
||||
# Wait for the subprocess to finish
|
||||
stdout, stderr = await process.communicate()
|
||||
# Run the actual task (this is the process-blocking instruction)
|
||||
output = subprocess.check_output([self.path+"/system.sh "+self.action], shell=True)
|
||||
|
||||
logger.debug("System action '"+self.action+"' completed with output:")
|
||||
logger.debug(stdout)
|
||||
logger.debug(output)
|
||||
|
||||
# Some kind of failure, so we can't run any commands this way
|
||||
if exitCode > 0:
|
||||
raise Exception("System task '"+self.action+"' failed")
|
||||
else:
|
||||
if self.callback:
|
||||
response = {
|
||||
'output': str(stdout)
|
||||
}
|
||||
self.callback(response, False)
|
||||
# And then, when complete, return to our callback
|
||||
if self.callback:
|
||||
response = {
|
||||
'output': str(output)
|
||||
}
|
||||
self.callback(response, False)
|
||||
|
||||
|
||||
##
|
||||
|
||||
Reference in New Issue
Block a user