Add some "pipe to self" trick in Pyro server to accelerate runtime shutdown instead of waiting for arbitrary pyro timeout.
--- a/runtime/PyroServer.py Thu Apr 18 14:32:43 2019 +0200
+++ b/runtime/PyroServer.py Thu Apr 18 14:34:22 2019 +0200
@@ -12,6 +12,7 @@
from __future__ import absolute_import
from __future__ import print_function
import sys
+import os
import Pyro
import Pyro.core as pyro
@@ -27,6 +28,7 @@
self.ip_addr = ip_addr
self.port = port
self.servicepublisher = None
+ self.piper, self.pipew = None, None
def _to_be_published(self):
return self.servicename is not None and \
@@ -60,8 +62,11 @@
self.daemon.connect(pyro_obj, "PLCObject")
when_ready()
- self.daemon.requestLoop()
- self.daemon.sock.close()
+ self.piper,self.pipew = os.pipe()
+ self.daemon.requestLoop(others=[self.piper], callback=lambda x:None)
+ self.piper, self.pipew = None, None
+ if hasattr(self,'sock'):
+ self.daemon.sock.close()
self.Unpublish()
def Restart(self):
@@ -70,6 +75,9 @@
def Quit(self):
self.continueloop = False
self.daemon.shutdown(True)
+ self.daemon.closedown()
+ if self.pipew is not None:
+ os.write(self.pipew, "goodbye")
def Publish(self):
self.servicepublisher = ServicePublisher("PYRO")