discuss-gnuradio
[Top][All Lists]
Advanced

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

?????? Multithreading error?


From: ????????
Subject: ?????? Multithreading error?
Date: Mon, 29 Nov 2021 19:56:04 +0800

Hi,
Thank you very much for your detailed answer. Although I have been in contact with GNURadio for a while, I have not used the PMT message port. I will take this opportunity to learn how to use the message port. Thanks again
Sincerely,
linge93


------------------ ???????? ------------------
??????: "Marcus M??ller" <mueller@kit.edu>;
????????: 2021??11??29??(??????) ????7:29
??????: "discuss-gnuradio"<discuss-gnuradio@gnu.org>;
????: Re: Multithreading error?

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), u8vec(re_img[0].tolist())
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,
Marcus


On 29.11.21 10:52, ???????? wrote:
> Hi,
> 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
>          while(i<n):
>              self.rxsymbols.append(in0[i])
>              i = i+1
>          rxsymbols_len = len(self.rxsymbols)
>          if rxsymbols_len == self.width*self.high//2+self.fillnum:
>              self.rxsymbols = np.array(self.rxsymbols)
>              self.rxsymbols.tofile("/home/liumaolin-2/PycharmProjects/test/model/sink_test")
>              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))
>              print(mse)
>
> plt.subplot(111)
>              plt.imshow(re_img[0]/255)
>              plt.show()
>
>          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!
> Sincerely,
> linge93


reply via email to

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