Nope, threading was the best approach (reinstated)

This commit is contained in:
James Barnsley
2020-01-01 21:41:38 +13:00
parent e6136505b4
commit fd66edfbe4
3 changed files with 73 additions and 47 deletions

View File

@ -1,20 +1,23 @@
from threading import Thread
import os, logging, subprocess, json, asyncio
import os, logging, subprocess, json
# import logger
logger = logging.getLogger(__name__)
class IrisSystemThread:
def __init__(self, action):
class IrisSystemThread(Thread):
def __init__(self, action, origin):
Thread.__init__(self)
self.action = action
self.origin = origin
self.path = os.path.dirname(__file__)
##
# Run the defined action
##
async def run(self):
def run(self):
logger.info("Running system action '"+self.action+"'")
callback_name = self.action+"_callback"
try:
self.can_run()
@ -40,14 +43,21 @@ class IrisSystemThread:
if stderr:
logger.error(stderr.decode())
return {
'error': stderr.decode()
}
getattr(self.origin, callback_name)(
None,
{
'error': stderr.decode()
}
)
else:
logger.info(stdout.decode())
return {
'output': stdout.decode()
}
getattr(self.origin, callback_name)(
{
'output': stdout.decode()
},
None
)
##