seanpar203 / event-bus Goto Github PK
View Code? Open in Web Editor NEWA simple python event bus.
License: MIT License
A simple python event bus.
License: MIT License
Hello, great lib, but ... :)
It is possible to use event-bus with class object/thread?
#!/usr/bin/env python3
import time
from threading import Thread
from event_bus import EventBus
bus = EventBus()
class Test(Thread):
def __init__(self, bus):
super(Test, self).__init__()
self.bus = bus
self.name = 'test'
self.daemon = True
@bus.on('test')
def test(self):
print('test')
test = Test(bus)
test.start()
while True:
bus.emit('test')
time.sleep(5)
This ends up with TypeError: test() missing 1 required positional argument: 'self'
Just add
long_description=open('README.md', encoding='utf-8').read(),
long_description_content_type='text/markdown',
to your setup.py and submit new release to https://pypi.org/project/event-bus/
Subscribe a function for more than one event.('event string in this case')...is this possible.
Thanks,
Hi,
I really love your project as it is not an overkill code block but an intelligent and efficient way to structure code event wise. But I would really love to see, that when using the threads argument, that the spawned thread should be daemonized by default or choosable by option.
I coded some applications with this library now but I always have the same problem, that when the main program ends all the threads are running further. This could be wanted but in most usecases it is not. I have coded a smarthome hub and the users can spawn own threads as they like by calling events.
By now they have to implement a kill flag into their own modules but I cannot rely on that. It should be possible to end the main thread and all spawned proccess of bus.emit('EVENT', threads=True) should end also. I guess this could be done by implementing the daemon option when the processes are spawned.
import threading
import time
import sys
def func():
while True:
time.sleep(0.5)
print('Thread alive, but it will die on program termination')
t1 = threading.Thread(target=func)
t1.daemon = True # CAN THIS BE IMPLEMENTED INTO YOUR PROJECT?
t1.start()
time.sleep(2)
sys.exit()
Sorry for bad looking code. I have no clue how to use that #*+#'§$§ code feature :-)
What do you think?
regards
Chris
Hi,
very nice work. I like good solutions that are not overloaded with features.
One thing would be nice. Normally you can decorate different functions with the event to fire them.
Is it possible to decorate a function in a way that it is fired at every event?
This would be nice for a separate logging or console functions.
regards
Chris
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.