So after a lot of prints and head scratching I found the problem, or at least a
solution which looks like it works....
I was using 'gtk.gdk.threads_enter()/leave()' in the non GTK thread,
but not in the display thread which was calling functions to set the
signals for the grabber.
I had to ensure that 'gtk.gdk.threads_enter()' was called before 'gtk_main()':
--
if (options.gui == True):
gtk.gdk.threads_enter()
gtk.main()
gtk.gdk.threads_leave()
--
and then for each of the functions calling the grabber, ensure that
'gtk.gdk.threads_leave()' was called:
--
def button2_clicked(self, widget):
global grabber
gtk.gdk.threads_leave()
grabber.stop_stream()
gtk.gdk.threads_enter()
--
Code now behaves a lot better, just one minor glitch (in the same manner) when
I trap 'Control+C' from command line.
Simon.
On Mon, 30 Mar 2009 09:06:05 -0600
Simon Wood <[email protected]> wrote:
> Hi all,
> I've got some weird behaviour with my little python app. It opens up a video
> device and streams the images to pyGTK window.
>
> It basically works OK but occasionally has issues when stopping the stream.
> It appears to get stuck in a while loop whilst waiting for a signal to clear.
>
> So questions:
> 1) is waiting for a signal to clear in this manner the best approach.
> 2) is there a way to debug what is really happening in the various threads?
>
> A code snippet is:
> --
> class pyv4l2_grabber(threading.Thread):
> --
> def stop_stream(self):
> if self.active == 1:
> self.event_stop_stream.set()
> self.active = 0
> while self.event_stop_stream.isSet():
> time.sleep(0.1)
> print "stopped capture, frame rate was ",
> (self.frame_count /(self.end_time - self.start_time))
> --
>
> It appears that when 'stop' fails I can wait as long as I want, but when ever
> I press control-C it reports:
> --
> CTraceback (most recent call last):
> File "./pyDataMatrixScanner.py", line 329, in button2_clicked
> self.videodevice.stop_stream()
> File "./pyDataMatrixScanner.py", line 170, in stop_stream
> time.sleep(0.1)
> KeyboardInterrupt
> --
>
>
> The code which actually draws the image to the screen/gtk-pixmap is
> surrounded by:
> --
> gtk.gdk.threads_enter()
> ...
> gtk.gdk.threads_leave()
> --
>
> which seem to be required for speed. If these are removed (or the drawing to
> screen is disabled) the lockup does not occur.... very strange.
>
> Any suggestions?
> Simon.
>
> _______________________________________________
> clug-talk mailing list
> [email protected]
> http://clug.ca/mailman/listinfo/clug-talk_clug.ca
> Mailing List Guidelines (http://clug.ca/ml_guidelines.php)
> **Please remove these lines when replying
_______________________________________________
clug-talk mailing list
[email protected]
http://clug.ca/mailman/listinfo/clug-talk_clug.ca
Mailing List Guidelines (http://clug.ca/ml_guidelines.php)
**Please remove these lines when replying