--- a/runtime/Worker.py Thu Sep 28 18:00:21 2023 +0200
+++ b/runtime/Worker.py Thu Sep 28 18:14:57 2023 +0200
@@ -8,9 +8,7 @@
# See COPYING.Runtime file for copyrights details.
-from threading import Lock, Condition, Thread
+from threading import Lock, Condition, Thread, get_ident @@ -64,7 +62,7 @@
meant to be called by worker thread (blocking)
- self._threadID = _thread.get_ident()
+ self._threadID = get_ident() @@ -75,13 +73,10 @@
- if self.job is not None:
+ self.todo.wait_for(self.job is not None) def interleave(self, waker, stopper, *args, **kwargs):
@@ -90,39 +85,42 @@
additionaly, it creates a new thread to wait for new job.
self.feed = Condition(self.mutex)
- self._threadID = _thread.get_ident()
+ self._threadID = get_ident() + if self.job is not None:
- _job = job(*args, **kwargs)
+ self.job = job(*args, **kwargs) + self.done.wait_for(lambda: self.job.success is not None) + if not self.job.success:
- if self.job is not None:
+ self.todo.wait_for(lambda: self.job is not None)
+ self.done.wait_for(lambda: self.job.success is not None) self.own_thread = Thread(target = wakerfeedingloop)
@@ -135,7 +133,7 @@
@@ -149,7 +147,7 @@
_job = job(*args, **kwargs)
- if self._threadID == _thread.get_ident():
+ if self._threadID == get_ident(): # if caller is worker thread execute immediately
@@ -159,13 +157,11 @@
raise EOFError("Worker is disabled")
- while self.job is not None:
+ self.free.wait_for(lambda: self.job is None)
+ self.done.wait_for(lambda: _job.success is not None)