[zeromq-dev] Designing a new architecture

andrea crotti andrea.crotti.0 at gmail.com
Tue Aug 7 15:47:52 CEST 2012

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://"

class SampleCmd(cmd.Cmd):
    def __init__(self, query):
        self.query = query

    def do_list(self, testid):
        """List all the commands
        print(self.query.recv().split(' '))

class SmartProcess(Process):
    def __init__(self):
        context = zmq.Context()
        self.socket = context.socket(zmq.REP)

    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)
    return socket

if __name__ == '__main__':
    qobj = query_obj()
    cmd = SampleCmd(qobj)

More information about the zeromq-dev mailing list