runtime/Worker.py
changeset 2537 eb4a4cc41914
parent 2536 2747d6e72eb8
child 2604 c8a25a3a7f8b
equal deleted inserted replaced
2536:2747d6e72eb8 2537:eb4a4cc41914
     7 #
     7 #
     8 # See COPYING.Runtime file for copyrights details.
     8 # See COPYING.Runtime file for copyrights details.
     9 
     9 
    10 from __future__ import absolute_import
    10 from __future__ import absolute_import
    11 import sys
    11 import sys
    12 import thread
       
    13 from threading import Lock, Condition
    12 from threading import Lock, Condition
    14 import six
    13 import six
       
    14 from six.moves import _thread
    15 
    15 
    16 
    16 
    17 class job(object):
    17 class job(object):
    18     """
    18     """
    19     job to be executed by a worker
    19     job to be executed by a worker
    63 
    63 
    64     def runloop(self, *args, **kwargs):
    64     def runloop(self, *args, **kwargs):
    65         """
    65         """
    66         meant to be called by worker thread (blocking)
    66         meant to be called by worker thread (blocking)
    67         """
    67         """
    68         self._threadID = thread.get_ident()
    68         self._threadID = _thread.get_ident()
    69         self.mutex.acquire()
    69         self.mutex.acquire()
    70         if args or kwargs:
    70         if args or kwargs:
    71             _job = job(*args, **kwargs)
    71             _job = job(*args, **kwargs)
    72             _job.do()
    72             _job.do()
    73             if not _job.success:
    73             if not _job.success:
    91         blocking until job done
    91         blocking until job done
    92         """
    92         """
    93 
    93 
    94         _job = job(*args, **kwargs)
    94         _job = job(*args, **kwargs)
    95 
    95 
    96         if self._threadID == thread.get_ident():
    96         if self._threadID == _thread.get_ident():
    97             # if caller is worker thread execute immediately
    97             # if caller is worker thread execute immediately
    98             _job.do()
    98             _job.do()
    99         else:
    99         else:
   100             # otherwise notify and wait for completion
   100             # otherwise notify and wait for completion
   101             self.mutex.acquire()
   101             self.mutex.acquire()