So now I tried the following, the smart process runs a subprocess in
background, the samplecmd should send the LIST query, but it just
hangs there, and I don't get any answer..
Is there anything missing (can't find anything there)?
import zmq
import cmd2 as cmd
from multiprocessing import Process
from subprocess import Popen, PIPE
SOCK = "tcp://127.0.0.1:4444"
class SampleCmd(cmd.Cmd):
def __init__(self, query):
cmd.Cmd.__init__(self)
self.query = query
def do_list(self, testid):
"""List all the commands
"""
self.query.send('LIST')
print(self.query.recv().split(' '))
class SmartProcess(Process):
def __init__(self):
Process.__init__(self)
context = zmq.Context()
self.socket = context.socket(zmq.REP)
self.socket.bind(SOCK)
def run(self):
# should be able to preempt, maybe running the subprocess in background
long_proc = Popen(['ls', '-l'], stdout=PIPE, stderr=PIPE)
print("after the long process is run")
# the above is not blocking
while True:
query = self.socket.recv()
if query == 'LIST':
self.socket.send('long list of things')
def query_obj():
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect(SOCK)
return socket
if __name__ == '__main__':
qobj = query_obj()
SmartProcess().start()
cmd = SampleCmd(qobj)
cmd.cmdloop()
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev