Actually I'm very happy to see that this works exactly as expected, I
can communicate with a process asking querying the status, still open
for other suggestions..
__metaclass__ = type
import sys
import zmq
from time import sleep
PORT = 'tcp://*:5554'
from threading import Thread
class Monitor(Thread):
def __init__(self, proc):
Thread.__init__(self)
self.proc = proc
context = zmq.Context()
self.socket = context.socket(zmq.REP)
self.socket.bind(PORT)
def run(self):
while True:
query = self.socket.recv()
self.socket.send(str(self.proc.status))
class Proc:
def __init__(self):
self.status = 0
def run(self):
while True:
self.status += 1
sleep(2)
def start_proc_and_monitor():
pr = Proc()
thr = Monitor(pr)
print("starting the monitor thread")
thr.start()
#only start in the end
pr.run()
def start_query():
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect(PORT)
while True:
raw_input("ask for status?")
socket.send('status')
ans = socket.recv()
print("status now = ", ans)
if __name__ == '__main__':
if len(sys.argv) > 1:
start_proc_and_monitor()
else:
start_query()
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev