|
From: | Marcus Müller |
Subject: | Re: [Discuss-gnuradio] matplotlib runtime error |
Date: | Fri, 2 May 2014 14:49:32 +0200 |
The custom block (perform plotting) is written in Python, as below:Gurus,I try to transfer an image file via a pair of USRPs.Unfortunately, in the work() function, the pyplot.draw() causes below runtime error.
At the receiver side, the data is fed into a custom block, where it plots the image in realtime using matplotlib's pyplot.imshow().
handler caught exception: main thread is not in main loop
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gnuradio/gr/gateway.py", line 55, in eval
try: self._callback()
File "/usr/local/lib/python2.7/dist-packages/gnuradio/gr/gateway.py", line 160, in __gr_block_handle
) for i in self.__out_indexes],
File "/usr/local/lib/python2.7/dist-packages/activecat/image_sink1.py", line 72, in work
self.axes1.figure.canvas.draw() #pyplot.draw()
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 349, in draw
tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/tkagg.py", line 13, in blit
tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox_array))
RuntimeError: main thread is not in main loop
thread[thread-per-block[1]: <block image_sink1 (2)>]: caught unrecognized exception
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy
from gnuradio import gr
from matplotlib import image, pyplot
class image_sink1(gr.sync_block):
def __init__(self):gr.sync_block.__init__( self, name="image_sink1",
in_sig=[ numpy.complex64 ],
out_sig=None)
pyplot.figure()
pyplot.ion()
pyplot.show()
self.axes1 = pyplot.gca()
#self.win = self.axes1.figure.canvas.manager.window
#self.win.after(100,animate)
self.completed = False
self.img2 = numpy.zeros( (150,150,4), numpy.uint8 )
self.coordinate = self.coordinate_stream()
def coordinate_stream(self):
for y in range(150):
for x in range( 0, 150, 2 ):
yield y,x
def work(self, input_items, output_items):
in0 = input_items[0]
if self.completed:
return -1
for sample1 in in0:
try:
y,x = next( self.coordinate )
if sample1.real > 0:
self.img2[y,x] = numpy.array([255,255,255,255])
else:
self.img2[y,x] = numpy.array([0,0,0,255])
if sample1.imag > 0:
self.img2[y,x+1] = numpy.array([255,255,255,255])
else:
self.img2[y,x+1] = numpy.array([0,0,0,255])
except StopIteration:
print "Receiver side completed!"
self.complete = True
self.axes1.imshow( self.img2 )
self.axes1.figure.canvas.draw() # or, pyplot.draw(), both gives error !!!
return in0.sizePlease advise,
thanks in advance.
_______________________________________________
Discuss-gnuradio mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
[Prev in Thread] | Current Thread | [Next in Thread] |