Reconfigure example with lock/disconnect/connect/unlock code hangs randomly

Hey guys,
I have written some example code to learn how to dynamically
reconfigure gnuradio based on events generated by probe blocks and a
watcher thread.
First I thought everything is running very well but later I noticed
that the program hangs if you let it run long enough.
If you uncomment the sleep(0.0001) it seems to be working fine but says:

“Exception in thread Thread-1 (most likely raised during interpreter
shutdown)”

We are running Ubuntu 10.10 over here.

Can somebody please run the code and confirm this?
Looks like a bug for me.


#!/usr/bin/env python

from gnuradio import gr
import gnuradio.gr.gr_threading as _threading
from time import sleep

class h_block_one(gr.hier_block2):
def init(self):
gr.hier_block2.init(self, “foo”,
gr.io_signature(0, 0, 0),
gr.io_signature(0, 0, 0))

    vec = range(100)

    self.source = gr.vector_source_f(vec,True,1)
    self.probe = gr.probe_signal_f()
    self.sink = gr.null_sink(gr.sizeof_float)
    self.connect(self.source, self.probe)

def level_one(self):
    return self.probe.level()

class h_block_two(gr.hier_block2):
def init(self):
gr.hier_block2.init(self, “bar”,
gr.io_signature(0, 0, 0),
gr.io_signature(0, 0, 0))

    vec = range(100)

    self.source = gr.vector_source_f(vec,True,1)
    self.probe = gr.probe_signal_f()
    self.sink = gr.null_sink(gr.sizeof_float)
    self.connect(self.source, self.probe)

def level_two(self):
    return self.probe.level()

class probe_this(gr.top_block):

def __init__(self):
    gr.top_block.__init__(self, 'Probe Reconfigure Test')

    self.h_block_one = h_block_one()
    self.h_block_two = h_block_two()
    self.connect(self.h_block_one)

def level_one(self):
    return self.h_block_one.level_one()

def level_two(self):
    return self.h_block_two.level_two()

def reconfigure(self):
    self.lock()
    self.disconnect(self.h_block_one)
    self.connect(self.h_block_two)
    self.unlock()

def conf_back(self):
    self.lock()
    self.disconnect(self.h_block_two)
    self.connect(self.h_block_one)

sleep(0.0001)

    self.unlock()

class _probe_watcher_thread(_threading.Thread):
def init(self, level_one, reconfigure, level_two, conf_back):
_threading.Thread.init(self)
self.setDaemon(1)
self.level_one = level_one
self.reconfigure = reconfigure
self.level_two = level_two
self.conf_back = conf_back
self.confed = False
self.keep_running = True
self.start()

def run(self):
    while self.keep_running:
        if self.confed:
            if self.level_two() > 50:
                self.conf_back()
                self.confed = False
                print 'reconfiguring'
        else:
            if self.level_one() > 50:
                self.reconfigure()
                self.confed = True
                print 'reconfiguring back'

if self.level_one and self.level_two:

print ‘foo’, self.level_one()

print ‘bar’, self.level_two()

if name==“main”:

def callback(msg):
    print 'received:', msg

tb = probe_this()
watcher = 

_probe_watcher_thread(tb.level_one,tb.reconfigure,tb.level_two,tb.conf_back)
tb.start()

sleep(100)

There should be another sleep in the reconfigure method to make it
working fine.

def reconfigure(self):
self.lock()
self.disconnect(self.h_block_one)
self.connect(self.h_block_two)
sleep(0.0001)
self.unlock()

I am not sure how long we have to sleep in order to fix the problem.

  • Johannes