
| Current Path : /var/www/web-klick.de/dsh/50_1/1313__procpyjs/src/python/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/web-klick.de/dsh/50_1/1313__procpyjs/src/python/networking.py |
import zerorpc
from processing import ProcessManager
"""
this module allows to access the process manager (see processing module) over a tcp socket
all functions inside the ProcessManager class can be accessed either with the command line
tool of zerorpc (installed along with the zerorcp python module) or via implementations of
zerorpc (available for at least python and nodejs)
this is an easy way to allow communication between clients and the server without the need
of implementing a library to connect them explicitly. however, this interface is for now just
a quick and dirty solution until we implement something better or that its suitable for production needs
see http://www.zerorpc.io/ for more information on how to use this
"""
default_bind_address = "tcp://127.0.0.1:4242"
class Server(object):
def __init__(self, target_class, bind_address=default_bind_address):
self.cls = target_class
self.bind_addresses = bind_address
def serve(self):
s = zerorpc.Server(self.cls())
s.bind(self.bind_addresses)
s.run()
class ProcmanInterface(Server):
def __init__(self, bind_address=default_bind_address):
super(ProcmanInterface, self).__init__(ProcessManager, bind_address)
import multiprocessing
if __name__ == "__main__":
p = multiprocessing.Process(target=ProcmanInterface().serve)
p.start()
import time
from processing import log
while True:
time.sleep(2)
log("server running...")