Changeset 8928

Show
Ignore:
Timestamp:
07/17/08 15:11:38
Author:
eb
Message:

C now interrupts top_block.run() and top_block.wait(), even in python's main thread.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gnuradio/branches/features/mp-sched/gnuradio-core/src/python/gnuradio/gr/top_block.py

    r6669 r8928  
    2222from gnuradio_swig_python import top_block_swig, \ 
    2323    top_block_wait_unlocked, top_block_run_unlocked 
     24 
     25#import gnuradio.gr.gr_threading as _threading 
     26import gr_threading as _threading 
     27 
     28 
     29# 
     30# There is no problem that can't be solved with an additional 
     31# level of indirection... 
     32# 
     33# This kludge allows ^C to interrupt top_block.run and top_block.wait 
     34# 
     35class _top_block_waiter(_threading.Thread): 
     36    def __init__(self, tb): 
     37        _threading.Thread.__init__(self) 
     38        self.setDaemon(1) 
     39        self.tb = tb 
     40        self.event = _threading.Event() 
     41        self.start() 
     42 
     43    def run(self): 
     44        top_block_wait_unlocked(self.tb) 
     45        self.event.set() 
     46 
     47    def wait(self): 
     48        while True: 
     49            self.event.wait(0.100) 
     50 
    2451 
    2552# 
     
    4976 
    5077    def run(self): 
    51         top_block_run_unlocked(self._tb) 
     78        self.start() 
     79        self.wait() 
    5280 
    5381    def wait(self): 
    54         top_block_wait_unlocked(self._tb) 
     82        _top_block_waiter(self._tb).wait() 
     83 
    5584 
    5685    # FIXME: these are duplicated from hier_block2.py; they should really be implemented