I am trying to make a python script that uses the multiprocessing module to produce 2 (or more) GTK windows. I am hitting a wall here it seems. Here is the code and the errors I am getting:
p1 = Process(target=tiny_gtk_process, name="process 1")
p1.start()
p2 = Process(target=tiny_gtk_process, name="process 2")
p2.start()
and:
def tiny_gtk_process():
import gtk
window = gtk.Window()
window.set_size_request(800,600)
window.show_all()
gtk.main()
Most of the time I am getting:
multiwin.py: Fatal IO error 0 (Success) on X server :0.0. python: ../../src/xcb_io.c:249: process_responses: Assertion `(((long) (dpy->last_request_read) - (long) (dpy->request)) <= 0)' failed.
Sometimes I get:
multiwin.py: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.0.
Is the issue the gtk loop? Doesn't multiprocessing isolate them?
Any ideas would be very helpful.
The problem is most likely that you are using multiprocessing.Process, which creates new processes using fork() instead of exec(). This means that each sub-process shares the same file handles as its parent, including those that connect it to the X server. The crash is caused because multiple processes are trying to communicate with the server simultaneously over the same connection.
A better solution would be to use subprocess.Popen or similar to start your processes. If you want multiprocessing-like communication between your processes, see my answer to this question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With