runtime/Worker.py
branchpython3
changeset 3753 5256e4bd92e6
parent 3750 f62625418bff
child 3846 cf027bfe2653
equal deleted inserted replaced
3752:9f6f46dbe3ae 3753:5256e4bd92e6
     6 # Copyright (C) 2018: Edouard TISSERANT
     6 # Copyright (C) 2018: Edouard TISSERANT
     7 #
     7 #
     8 # See COPYING.Runtime file for copyrights details.
     8 # See COPYING.Runtime file for copyrights details.
     9 
     9 
    10 
    10 
    11 import sys
       
    12 from threading import Lock, Condition, Thread
    11 from threading import Lock, Condition, Thread
    13 
    12 
    14 import six
    13 import _thread
    15 from six.moves import _thread
       
    16 
    14 
    17 
    15 
    18 class job(object):
    16 class job(object):
    19     """
    17     """
    20     job to be executed by a worker
    18     job to be executed by a worker
    31         """
    29         """
    32         try:
    30         try:
    33             call, args, kwargs = self.job
    31             call, args, kwargs = self.job
    34             self.result = call(*args, **kwargs)
    32             self.result = call(*args, **kwargs)
    35             self.success = True
    33             self.success = True
    36         except Exception:
    34         except Exception as e:
    37             self.success = False
    35             self.success = False
    38             self.exc_info = sys.exc_info()
    36             self.exc_info = e
    39 
    37 
    40 
    38 
    41 class worker(object):
    39 class worker(object):
    42     """
    40     """
    43     serialize main thread load/unload of PLC shared objects
    41     serialize main thread load/unload of PLC shared objects
    58     def reraise(self, job):
    56     def reraise(self, job):
    59         """
    57         """
    60         reraise exception happend in a job
    58         reraise exception happend in a job
    61         @param job: job where original exception happend
    59         @param job: job where original exception happend
    62         """
    60         """
    63         exc_type = job.exc_info[0]
    61         raise job.exc_info
    64         exc_value = job.exc_info[1]
       
    65         exc_traceback = job.exc_info[2]
       
    66         six.reraise(exc_type, exc_value, exc_traceback)
       
    67 
    62 
    68     def runloop(self, *args, **kwargs):
    63     def runloop(self, *args, **kwargs):
    69         """
    64         """
    70         meant to be called by worker thread (blocking)
    65         meant to be called by worker thread (blocking)
    71         """
    66         """