Matplotlib with Multiprocess Freeze Computer

I have a problem with matplotlib and multiprocessing. I start the first process, where I show the image and select the area, and close the shape. Then I start another process when I call the chart function, which is updated regularly. Up to this point, everything is working fine. Then, when I try to start another process using the SAME graph function, it freezes my entire computer, BUT the background processes work ... I have only one of these errors (this is not always the same thing):

error 1:

XIO: fatal error IO 25 (inappropriate ioctl for the device) on the X server ": 0.0" after 4438 requests (4438 known processed) with 30 events. XIO: fatal I / O error 11 (resource temporarily unavailable) on server X ": 0.0" after 4443 requests (4443 known processed) with 31 remaining events. [xcb] Unknown sequence number during queue processing [xcb] Most likely, this is a multithreaded client, and XInitThreads was not called [xcb] Aborting, sorry for that. python: .. /../src/xcb_io.c:274: poll_for_event: Statement `! xcb_xlib_threads_sequence_lost 'failed.

error 2:

X Failed request error: BadIDChoice (invalid resource identifier for this connection was selected) Main request operation code: 53 (X_CreatePixmap) Resource identifier in the failed request: 0x5600299 Sequential number of the failed request: 4793 Current serial number on the output stream: 4795 XIO: fatal error IO 25 (inappropriate ioctl for the device) on server X ": 0.0" after 4788 requests (4788 known processed) with 31 remaining events. XIO: fatal error IO 25 (inappropriate ioctl for the device) on the X server ": 0.0" after 4793 requests (4793 known processed) with 32 events.

The strange part is that I can completely start several processes that call the graph function without any problems, this is the connection with the first graph, which makes it unstable.

While trying to debug, I found that a simple fig=plt.figure() enough to collapse everything: in fact, any plt call ...

I read here and there that you can get matplotlib to use the agg backend and it helps with the multiprocessing process, but some widgets don't work with it, so I would like to avoid that.

I do not understand why using matplotlib in different processes can cause problems, so if someone could explain the reasons and / or help me with a workaround, it would be very nice.

+5
source share
2 answers

I had a very similar problem in which I have a class that creates graphs in parallel. The first time I create a new instance of this class and start the graphing function, everything works fine. But if I create a new copy and plot, everything freezes.

I fixed it by writing a bash script, which in turn would run a python script with code to invoke an instance of one class + plot. In other words, closing python between one plot call and the next makes a clean slate of your working environment that the computer no longer freezes. This is not an optimal solution, but it works :)

0
source

Since I can not comment, a little advice as an answer. If you are on a Linux machine or you have access via ssh, you can defrost the computer by switching to the terminal and kill all the script processes. This will enable the X input again. If you don't have other python processes, the easiest way is

 killall python # python3 if you use version 3 

or if you want to be careful

 ps as | grep python kill # add PID numbers of processes here 
0
source

All Articles