Pub sub implementation
Project description
Event Channel
Another library with a pub/sub implementation. You can subscribe functions to a certain topic (aka event). When a message is sent through this event callback functions subscribed will be executed.
from event_channel import EventChannel
mychannel = EventChannel() # You can also import channel, is an instance already created
def callback(x):
x = x + 1
print(x)
mychannel.subscribe("myevent", callback)
mychannel.publish("myevent", 345)
channel.unsubscribe("myevent", callback)
from event_channel.threaded_event_channel import ThreadedEventChannel
mychannel = ThreadedEventChannel(blocking=False) # You can also import non_blocking_channel, is an instance already created
def callback(x):
x = x + 1
print(x)
mychannel.subscribe("myevent", callback)
mychannel.subscribe("myevent", callback2)
threads = mychannel.publish("myevent", 345)
# Wait thread finish
for thread in threads:
thread.join()
from event_channel.threaded_event_channel import ThreadedEventChannel
my_blocking_channel = ThreadedEventChannel() # You can also import channel, is an instance already created
def callback(x):
x = x + 1
print(x)
mychannel.subscribe("myevent", callback)
mychannel.subscribe("myevent", callback2)
threads = mychannel.publish("myevent", 345)
#at this point all threads are finished
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
event_channel-0.4.3.tar.gz
(14.9 kB
view hashes)
Built Distribution
Close
Hashes for event_channel-0.4.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b52381b9affc02e83ce4cd2a16096b747df8ce1c7a84a62bd9f23a959d51d0d |
|
MD5 | e5e682226ffe90eecc352523f29cfc09 |
|
BLAKE2b-256 | d11b25a18971f457072cfc3b519ad0a635132b55638e7a193ae2a8de96407ae8 |