[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multithreading error?

From: Marcus Müller
Subject: Re: Multithreading error?
Date: Mon, 29 Nov 2021 12:29:37 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0

Using matplotlib from a work method is simply a bad idea. Don't do it! (I think we spoke about that in chat, didn't we?)

I'd recommend instead:

0. Add a "QT GUI Graphic Item" to your flow graph in GRC
1. Add a message output port to your block, call it e.g. "image_data"
2. in your work() method, calculate the image you want to display (i.e. your 
re_img[0] )
3. send a PMT message that's a cons( cons(width, height), 
4. Implement a Python block that has a message output port "image_file", and a message input port "image_data", with a message handler, which
   1. takes the data from the PMT
   2. uses the `cv2` python library to convert the data to an image,
   3. uses the `tempfile` library to write that to temporary file
   4. send that filename to the message output port
5. connect your signal processing block's "image_data" output to your picture-writing block's "image_data" input 6. connect your picture-writing block's "image_file" output to QT GUI Graphic Item's "filename" input

Best regards,

On 29.11.21 10:52, 能书能言 wrote:
I designed a Python OOT sink block. The purpose of this block is to get the input characters and store it in a variable. I can run a tensorflow model through this variable to restore it to the original image. My work function is as follows:
  def work(self, input_items, output_items):
         in0 = input_items[0]
         n = len(in0)
         i = 0
             i = i+1
         rxsymbols_len = len(self.rxsymbols)
         if rxsymbols_len == self.width*self.high//2+self.fillnum:
             self.rxsymbols = np.array(self.rxsymbols)
             rx = self.rxsymbols[0:self.width*self.high//2]
            rv_img = np.concatenate([np.reshape(np.real(rx), [1, -1]), np.reshape(np.imag(rx), [1, -1])], axis=0)
             rv_img = np.reshape(rv_img, self.inter_shape)
             re_img = self.de_model.predict(rv_img)
             mse = np.mean(np.square(re_img-self.img_array))


         return len(input_items[0])

But when I clicked to run the flow graph, the following error occurred:
Exception ignored in: <function Image.__del__ at 0x7fd68942b4c0>
Traceback (most recent call last):
    File "/usr/lib/python3.8/tkinter/__init__.py", line 4017, in __del__
      self.tk.call('image','delete', self.name)
RuntimeError: main thread is not in main loop
Tcl_AsyncDelete: async handler deleted by the wrong thread

This seems to be a problem with matplotlib drawing. In fact, the final result is that I can restore the picture I want. In other words, the basic functions can be realized now, but the error prompted by the terminal does not look good. , I want to make it perfect, if anyone has some good suggestions I would not be very grateful, thank you!

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]