https://github.com/mandrewcito/event_channel
Tiny pub sub implentation
https://github.com/mandrewcito/event_channel
pubsub python python3
Last synced: about 1 month ago
JSON representation
Tiny pub sub implentation
- Host: GitHub
- URL: https://github.com/mandrewcito/event_channel
- Owner: mandrewcito
- License: gpl-3.0
- Created: 2019-05-24T05:12:12.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2023-01-15T21:16:34.000Z (over 2 years ago)
- Last Synced: 2025-03-15T19:17:53.519Z (about 2 months ago)
- Topics: pubsub, python, python3
- Language: Python
- Homepage:
- Size: 43.9 KB
- Stars: 10
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Event Channel
[](https://www.paypal.me/mandrewcito/1)

[](https://pepy.tech/project/event-channel)
[](https://pepy.tech/project/event-channel/month)



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.
```python
from event_channel import EventChannelmychannel = 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)
``````python
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()
``````python
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```