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"                 
                                                                   
<[email protected]&gt;;
????????:&nbsp;2021??11??29??(??????) ????7:29
??????:&nbsp;"discuss-gnuradio"<[email protected]&gt;;

????:&nbsp;Re: Multithreading error?



Using matplotlib from a work method is simply a bad idea. Don't do it!&nbsp; (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
&nbsp;&nbsp;&nbsp; 1. takes the data from the PMT
&nbsp;&nbsp;&nbsp; 2. uses the `cv2` python library to convert the data to an 
image,
&nbsp;&nbsp;&nbsp; 3. uses the `tempfile` library to write that to temporary 
file
&nbsp;&nbsp;&nbsp; 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:
&gt; Hi,
&gt; I designed a Python OOT sink block. The purpose of this block is to get 
the input 
&gt; characters and store it in a variable. I can run a tensorflow model 
through this variable 
&gt; to restore it to the original image. My work function is as follows:
&gt;&nbsp; &nbsp;def work(self, input_items, output_items):
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; in0 = input_items[0]
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n = len(in0)
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i = 0
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while(i<n):
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
self.rxsymbols.append(in0[i])
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i = i+1
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rxsymbols_len = len(self.rxsymbols)
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if rxsymbols_len == 
self.width*self.high//2+self.fillnum:
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.rxsymbols = 
np.array(self.rxsymbols)
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
self.rxsymbols.tofile("/home/liumaolin-2/PycharmProjects/test/model/sink_test")
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rx = 
self.rxsymbols[0:self.width*self.high//2]
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rv_img = 
np.concatenate([np.reshape(np.real(rx), [1, -1]), 
&gt; np.reshape(np.imag(rx), [1, -1])], axis=0)
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rv_img = 
np.reshape(rv_img, self.inter_shape)
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; re_img = 
self.de_model.predict(rv_img)
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mse = 
np.mean(np.square(re_img-self.img_array))
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(mse)
&gt; 
&gt; plt.subplot(111)
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; plt.imshow(re_img[0]/255)
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; plt.show()
&gt; 
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return len(input_items[0])
&gt; 
&gt; But when I clicked to run the flow graph, the following error occurred:
&gt; Exception ignored in: <function Image.__del__ at 0x7fd68942b4c0&gt;
&gt; Traceback (most recent call last):
&gt;&nbsp; &nbsp; &nbsp;File "/usr/lib/python3.8/tkinter/__init__.py", line 
4017, in __del__
&gt;&nbsp; &nbsp; &nbsp; &nbsp;self.tk.call('image','delete', self.name)
&gt; RuntimeError: main thread is not in main loop
&gt; Tcl_AsyncDelete: async handler deleted by the wrong thread
&gt; 
&gt; This seems to be a problem with matplotlib drawing. In fact, the final 
result is that I 
&gt; can restore the picture I want. In other words, the basic functions can be 
realized now, 
&gt; but the error prompted by the terminal does not look good. , I want to 
make it perfect, if 
&gt; anyone has some good suggestions I would not be very grateful, thank you!
&gt; Sincerely,
&gt; linge93

Reply via email to