Matplotlib with multiprocessing freeze computer

2024/11/13 6:39:25

I have an issue with matplotlib and multiprocessing. I launch a first process, where I display an image and select an area, and close the figure. Then I launch another process, where I call a graph function that is regularly updated. Up this point, eveything works fine. Then when I try to launch another process with the SAME graph function, it freeze my whole computer, BUT the background processes stil work... I only have one of these errors (it's not always the same):

error 1 :

XIO: fatal IO error 25 (Inappropriate ioctl for device) on X server":0.0"after 4438 requests (4438 known processed) with 30 events remaining. XIO: fatal IO error 11 (Resource temporarily unavailable)on X server ":0.0"after 4443 requests (4443 known processed) with 31 events remaining. [xcb] Unknown sequence number while processing queue [xcb]Most likely this is a multi-threaded client and XInitThreads has notbeen called [xcb] Aborting, sorry about that. python:../../src/xcb_io.c:274: poll_for_event: Assertion`!xcb_xlib_threads_sequence_lost' failed.

error 2 :

X Error of failed request: BadIDChoice (invalid resource ID chosenfor this connection) Major opcode of failed request: 53(X_CreatePixmap) Resource id in failed request: 0x5600299 Serialnumber of failed request: 4793 Current serial number in outputstream: 4795 XIO: fatal IO error 25 (Inappropriate ioctl for device)on X server ":0.0"after 4788 requests (4788 known processed) with 31 events remaining. XIO: fatal IO error 25 (Inappropriate ioctl for device) onX server ":0.0"after 4793 requests (4793 known processed) with 32 events remaining.

The weird part is that I can totaly launch several process calling the graph function without any issue, it's the coupling with the first plot that make it unstable.

When trying to debug, I found out that a simple fig=plt.figure() is enough to crash everything : in fact, any call to plt ...

I read here and there that you can force matplotlib to use the agg backend and it helps with the multiprocess, but some widgets doesn't work with it so I would like to avoid this.

I don't really understand why using matplotlib in differents processes could cause problems, so if anyone could explain the reasons and/or help me with a workaround, it would be very nice.

Answer

I just had a very similar issue in which I have a class which produces plots in parallel. The first time I create a new instance of that class and run the plotting function, everything works perfectly. But if I create a new instance and plot, everything freezes.

I fixed it by writing a bash script which will in turn run a python script with the code for a single class instantiation + plot call. In other words, closing python between one plot call and the next one makes a clean slate of your working environment the computer does not freeze anymore. This is not an optimal solution, but it's working :)

https://en.xdnf.cn/q/72213.html

Related Q&A

Pull Tag Value using BeautifulSoup

Can someone direct me as how to pull the value of a tag using BeautifulSoup? I read the documentation but had a hard time navigating through it. For example, if I had:<span title="Funstuff&qu…

What is the practical difference between xml, json, rss and atom when interfacing with Twitter?

Im new to web services and as an introduction Im playing around with the Twitter API using the Twisted framework in python. Ive read up on the different formats they offer, but its still not clear to m…

how to grab from JSON in selenium python

My page returns JSON http response which contains id: 14Is there a way in selenium python to grab this? I searched the web and could not find any solutions. Now I am wondering maybe its just not poss…

Numpy: Array of `arange`s

Is there a way to take...>>> x = np.array([0, 8, 10, 15, 50]).reshape((-1, 1)); ncols = 5...and turn it into...array([[ 0, 1, 2, 3, 4],[ 8, 9, 10, 11, 12],[10, 11, 12, 13, 14],[15, 16, 17…

Understanding model.summary Keras

Im trying to understand model.summary() in Keras. I have the following Convolutional Neural Network. The values of the first Convolution are: conv2d_4 (Conv2D) (None, 148, 148, 16) 448 …

Determine adjacent regions in numpy array

I am looking for the following. I have a numpy array which is labeled as regions. The numpy array represents a segmented image. A region is a number of adjacent cells with the same value. Each region h…

Python: win32gui.SetForegroundWindow

I have just written simple script to launch an applciation and I am trying to use "SendKeys" module to send keystrokes to this application. There is one "Snapshot" button, but I can…

Building PyCrypto with fastmath (gmp or mpir) via pip on Windows

I installed PyCrypto on Windows via pip but i was not able to build Crypto.PublicKey._fastmath because GMP was not found.I know there is a binary version on voidspace but i would like to build the late…

Get name of current test in setup using nose

I am currently writing some functional tests using nose. The library I am testing manipulates a directory structure. To get reproducible results, I store a template of a test directory structure and cr…

python: find html tags and replace their attributes [duplicate]

This question already has answers here:Replace SRC of all IMG elements using Parser(2 answers)Closed 10 years ago.I need to do the following:take html document find every occurrence of img tag take the…