bitween.components.pubsub package¶
Submodules¶
bitween.components.pubsub.autosubscriber module¶
Democlass for autosubscribing
needed for testing
-
class
bitween.components.pubsub.autosubscriber.AutoSub[source]¶ Bases:
bitween.components.pubsub.pubsub.SubscriberDemoclass for autosubscribing
needed for testing
bitween.components.pubsub.pubsub module¶
-
class
bitween.components.pubsub.pubsub.Subscriber(name='', autosubscribe=False)[source]¶ -
get_message(timeout=0.1)[source]¶ get topic, arguments and names arguments
Parameters: timeout – Returns: topic, args, kwargs Return type: str, list, dict
-
Module contents¶
PubSub for interprocess communication
holds topics to subscribe and methods to publish to those topics.
usage¶
basic:
# create the subscriber object ans subscribe to topic 'myTopic'
s = Subscriber()
s.subscribe('myTopic')
def loop():
while True:
if s.has_messages():
(topic, args, kwargs) = s.get()
print('%s, %s, %s' % topic, args, kwargs)
# (maybe from another thread and object) post to the topic:
publish('myTopic', 'somestring', val=123)
by subclassing:
class MySub(Subscriber):
def __init__(self):
super().__init__()
self.subscribe('myTopic')
self.loop()
def loop():
while True:
if self.has_messages():
(topic, args, kwargs) = self.get()
print('%s, %s, %s' % topic, args, kwargs)