[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r10647 - in gnuradio/branches/developers/eb/t348: gnur
From: |
eb |
Subject: |
[Commit-gnuradio] r10647 - in gnuradio/branches/developers/eb/t348: gnuradio-core/src/python/gnuradio/gr gr-utils/src/python |
Date: |
Thu, 19 Mar 2009 13:43:52 -0600 (MDT) |
Author: eb
Date: 2009-03-19 13:43:51 -0600 (Thu, 19 Mar 2009)
New Revision: 10647
Modified:
gnuradio/branches/developers/eb/t348/gnuradio-core/src/python/gnuradio/gr/top_block.py
gnuradio/branches/developers/eb/t348/gr-utils/src/python/usrp_siggen.py
Log:
A slight tweak of _top_block_waiter appears to have solved the "USRP
still blasting away after ^C" problem.
Modified:
gnuradio/branches/developers/eb/t348/gnuradio-core/src/python/gnuradio/gr/top_block.py
===================================================================
---
gnuradio/branches/developers/eb/t348/gnuradio-core/src/python/gnuradio/gr/top_block.py
2009-03-19 17:27:47 UTC (rev 10646)
+++
gnuradio/branches/developers/eb/t348/gnuradio-core/src/python/gnuradio/gr/top_block.py
2009-03-19 19:43:51 UTC (rev 10647)
@@ -32,6 +32,22 @@
#
# This kludge allows ^C to interrupt top_block.run and top_block.wait
#
+# The problem that we are working around is that Python only services
+# signals (e.g., KeyboardInterrupt) in its main thread. If the main
+# thread is blocked in our C++ version of wait, even though Python's
+# SIGINT handler fires, and even though there may be other python
+# threads running, no one will know. Thus instead of directly waiting
+# in the thread that calls wait (which is likely to be the Python main
+# thread), we create a separate thread that does the blocking wait,
+# and then use the thread that called wait to do a slow poll of an
+# event queue. That thread, which is executing "wait" below is
+# interruptable, and if it sees a KeyboardInterrupt, executes a stop
+# on the top_block, then goes back to waiting for it to complete.
+# This ensures that the unlocked wait that was in progress (in the
+# _top_block_waiter thread) can complete, release its mutex and back
+# out. If we don't do that, we are never able to clean up, and nasty
+# things occur like leaving the USRP transmitter sending a carrier.
+#
class _top_block_waiter(_threading.Thread):
def __init__(self, tb):
_threading.Thread.__init__(self)
@@ -45,8 +61,12 @@
self.event.set()
def wait(self):
- while not self.event.isSet():
- self.event.wait(0.100)
+ try:
+ while not self.event.isSet():
+ self.event.wait(0.100)
+ except KeyboardInterrupt:
+ self.tb.stop()
+ self.wait()
#
Modified:
gnuradio/branches/developers/eb/t348/gr-utils/src/python/usrp_siggen.py
===================================================================
--- gnuradio/branches/developers/eb/t348/gr-utils/src/python/usrp_siggen.py
2009-03-19 17:27:47 UTC (rev 10646)
+++ gnuradio/branches/developers/eb/t348/gr-utils/src/python/usrp_siggen.py
2009-03-19 19:43:51 UTC (rev 10647)
@@ -212,9 +212,6 @@
try:
tb.run()
except KeyboardInterrupt:
- print "KeyboardInterrupt!"
- tb.stop()
- tb.wait()
pass
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r10647 - in gnuradio/branches/developers/eb/t348: gnuradio-core/src/python/gnuradio/gr gr-utils/src/python,
eb <=