Git Product home page Git Product logo

event-bus's People

Contributors

controlnet avatar dependabot[bot] avatar seanpar203 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

event-bus's Issues

Use event-bus with class object

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'

Add the daemon option from the threading module

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

Is it possible to catch all events (e.g. for logging)?

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.