21 # License along with this library; if not, write to the Free Software |
21 # License along with this library; if not, write to the Free Software |
22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23 |
23 |
24 |
24 |
25 from __future__ import absolute_import |
25 from __future__ import absolute_import |
26 import thread |
|
27 from threading import Thread, Lock, Semaphore, Event, Condition |
26 from threading import Thread, Lock, Semaphore, Event, Condition |
28 import ctypes |
27 import ctypes |
29 import os |
28 import os |
30 import sys |
29 import sys |
31 import traceback |
30 import traceback |
32 from time import time |
31 from time import time |
33 import _ctypes # pylint: disable=wrong-import-order |
32 import _ctypes # pylint: disable=wrong-import-order |
34 import Pyro.core as pyro |
33 import Pyro.core as pyro |
35 import six |
34 import six |
|
35 from six.moves import _thread |
36 |
36 |
37 from runtime.typemapping import TypeTranslator |
37 from runtime.typemapping import TypeTranslator |
38 from runtime.loglevels import LogLevelsDefault, LogLevelsCount |
38 from runtime.loglevels import LogLevelsDefault, LogLevelsCount |
39 from runtime import PlcStatus |
39 from runtime import PlcStatus |
40 |
40 |
102 |
102 |
103 def runloop(self, *args, **kwargs): |
103 def runloop(self, *args, **kwargs): |
104 """ |
104 """ |
105 meant to be called by worker thread (blocking) |
105 meant to be called by worker thread (blocking) |
106 """ |
106 """ |
107 self._threadID = thread.get_ident() |
107 self._threadID = _thread.get_ident() |
108 if args or kwargs: |
108 if args or kwargs: |
109 job(*args, **kwargs).do() |
109 job(*args, **kwargs).do() |
110 # result is ignored |
110 # result is ignored |
111 self.mutex.acquire() |
111 self.mutex.acquire() |
112 while not self._finish: |
112 while not self._finish: |
126 blocking until job done |
126 blocking until job done |
127 """ |
127 """ |
128 |
128 |
129 _job = job(*args, **kwargs) |
129 _job = job(*args, **kwargs) |
130 |
130 |
131 if self._threadID == thread.get_ident() or self._threadID is None: |
131 if self._threadID == _thread.get_ident() or self._threadID is None: |
132 # if caller is worker thread execute immediately |
132 # if caller is worker thread execute immediately |
133 _job.do() |
133 _job.do() |
134 else: |
134 else: |
135 # otherwise notify and wait for completion |
135 # otherwise notify and wait for completion |
136 self.mutex.acquire() |
136 self.mutex.acquire() |