def __call__(self, msg): if not self.done.isSet(): # only expecting a single message self.messages.append((msg, current_thread_id())) self.done.set() else: raise Exception('Was only expecting a single message')
def __call__(self, msg): self.messages.append((msg, current_thread_id())) # this is the thread_id where the message is received if msg[1] == message_count: self.done.set() elif msg[1] > message_count: raise ValueError( ("Received a message index '%i' " "higher than max message_count %i"%( msg[1], message_count)))
def send_from_other_thread(): channel.send(('%s - thread %s'%(channel_name, current_thread_id()), -99))
chanY = bus.create_new_channel('X.Y') assert chanY.parent_channel == chanX assert chanX.name in bus.channels assert chanY.name in bus.channels bus.stop() def test_channel_management_nonthreaded(): test_channel_management(use_dedicated_thread_mode=False) def _test_subscriptions(async=False, threadlocal=False): bus = MessageBus(use_dedicated_thread_mode=async) bus.start() start_time = time_of_day() test_thread_id = current_thread_id() channels = {} channel_names = ('a', 'a.b', 'a.b.c', 'a.b.c.d', 'w.x.y.z') message_count = 200 class Subscriber(object): def __init__(self, channel_name): self.channel_name = channel_name self.messages = [] self.done = Event() def __call__(self, msg): self.messages.append((msg, current_thread_id())) # this is the thread_id where the message is received if msg[1] == message_count: self.done.set()