Threading plus multiprocessing plus cv2 error

John O'Hagan research at johnohagan.com
Sat Aug 29 04:24:10 EDT 2020


Dear list

Thanks to this list, I haven't needed to ask a question for
a very long time, but this one has me stumped.

Here's the minimal 3.8 code, on Debian testing:

-----
from multiprocessing import Process
from threading import Thread
from time import sleep
import cv2

def show(im, title, location):
    cv2.startWindowThread()
    cv2.namedWindow(title)
    cv2.moveWindow(title, *location)
    cv2.imshow(title, im)
    sleep(2) #just to keep window open

im1 = cv2.imread('/path/to/image1')
im2 = cv2.imread('/path/to/image2')

Thread(target=show, args=(im1, 'im1', (600,0))).start()
sleep(1)
Process(target=show, args=(im2, 'im2', (0, 0))).start()
-----

Here's the error:

-----
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has
not been called 
[xcb] Aborting, sorry about that.
python3: ../../src/xcb_io.c:260: poll_for_event: Assertion
`!xcb_xlib_threads_sequence_lost' failed.
-----

There's no error without the sleep(1), nor if the Process is started
before the Thread, nor if two Processes are used instead, nor if two
Threads are used instead. IOW the error only occurs if a Thread is
started first, and a Process is started a little later.

Any ideas what might be causing the error?

Thanks.

--

John


More information about the Python-list mailing list