Don't pass "context" to the child process. Create another context in the child. ZeroMQ objects don't work well across forks.
On Thu, Mar 27, 2014 at 10:42 PM, SUDRES Xavier <[email protected]>wrote: > I'm trying to run a very simple example code using pyzmq and > multiprocessing. I just want to have two threads communicating through an > zmq socket (inproc or ipc). > > I'm using the following code: > > import zmq > from multiprocessing import Process > > def main(): > > uri = "ipc:///tmp/FORK" > context = zmq.Context() > > pipe = context.socket(zmq.PAIR) > print("bind", uri) > pipe.bind(uri) > > p = Process(target=thread, args=(context, uri, zmq.PAIR)) > p.start() > > print("Fork done, receiving...") > print(pipe.recv_string()) > print("Received !!!") > > p.join() > del pipe > del context > > def thread(context, uri, socketType): > pipe = context.socket(socketType) > print("connect", uri) > pipe.connect(uri) > > print("Thread send Hello...") > pipe.send_string("Hello") > > main() > > Screen output = > bind ipc:///tmp/FORK > Forked, receiving... > connect ipc:///tmp/FORK > Thread send Hello... > > I'have detected a little error while installing the version of > pyzmq(master) using cython 0.20 : > Configure: Autodetecting ZMQ settings... > Custom ZMQ dir: > /home_local/xsudres/dev/src/LPISIS/COTS/ZEROMQ/work/zeromq > creating build/temp.linux-x86_64-3.4/scratch/tmp > cc -c /tmp/timer_create6cc83401.c -o > build/temp.linux-x86_64-3.4/scratch/tmp/timer_create6cc83401.o > cc build/temp.linux-x86_64-3.4/scratch/tmp/timer_create6cc83401.o -o > build/temp.linux-x86_64-3.4/scratch/a.out > build/temp.linux-x86_64-3.4/scratch/tmp/timer_create6cc83401.o: In > function `main': > timer_create6cc83401.c:(.text+0x15): undefined reference to `timer_create' > collect2: ld returned 1 exit status > gcc -pthread -Werror=declaration-after-statement -DNDEBUG -g -fwrapv -O3 > -Wall -Wstrict-prototypes -fPIC > -I/home_local/xsudres/dev/src/LPISIS/COTS/ZEROMQ/work/zeromq/include > -Izmq/utils -Izmq/backend/cython -Izmq/devices -c > build/temp.linux-x86_64-3.4/scratch/vers.c -o > build/temp.linux-x86_64-3.4/scratch/vers.o > gcc -pthread build/temp.linux-x86_64-3.4/scratch/vers.o > -L/home_local/xsudres/dev/src/LPISIS/COTS/ZEROMQ/work/zeromq/lib > -Wl,--enable-new-dtags,-R/home_local/xsudres/dev/src/LPISIS/COTS/ZEROMQ/work/zeromq/lib > -lzmq -lrt -o build/temp.linux-x86_64-3.4/scratch/vers > ZMQ version detected: 4.0.4 > > => undefined reference to `timer_create', is it important ? > > Thanks for your help, > > Xavier SUDRES > ------------------------------ > > Ce message et les pièces jointes sont confidentiels et réservés à l'usage > exclusif de ses destinataires. Il peut également être protégé par le secret > professionnel. Si vous recevez ce message par erreur, merci d'en avertir > immédiatement l'expéditeur et de le détruire. L'intégrité du message ne > pouvant être assurée sur Internet, la responsabilité du groupe Atos ne > pourra être engagée quant au contenu de ce message. Bien que les meilleurs > efforts soient faits pour maintenir cette transmission exempte de tout > virus, l'expéditeur ne donne aucune garantie à cet égard et sa > responsabilité ne saurait être engagée pour tout dommage résultant d'un > virus transmis. > > This e-mail and the documents attached are confidential and intended > solely for the addressee; it may also be privileged. If you receive this > e-mail in error, please notify the sender immediately and destroy it. As > its integrity cannot be secured on the Internet, the Atos group liability > cannot be triggered for the message content. Although the sender endeavors > to maintain a computer virus-free network, the sender does not warrant that > this transmission is virus-free and will not be liable for any damages > resulting from any virus transmitted. > > _______________________________________________ > zeromq-dev mailing list > [email protected] > http://lists.zeromq.org/mailman/listinfo/zeromq-dev > >
_______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
