Giter VIP home page Giter VIP logo

eventpy's Introduction

eventpy -- Python library for event dispatcher and callback list

eventpy is a Python event library that provides tools that enable your application components to communicate with each other by dispatching events and listening for them. With eventpy you can easily implement signal/slot mechanism, or observer pattern.
This library is the Python version rewritten from the C++ library eventpp, both are developed by the same developer.

Facts and features

  • Powerful
    • Supports synchronous event dispatching and asynchronous event queue.
    • Configurable and extensible with policies.
  • Robust
    • Supports nested event. During the process of handling an event, a listener can safely dispatch event and append/prepend/insert/remove other listeners.
    • Thread safety. Supports multi-threading.
    • Well tested. Backed by unit tests.
  • Flexible and easy to use
    • Listeners and events can be of any type and do not need to be inherited from any base class.
    • Requires Python 3. Tested with Python 3.7 and Cython.

License

Apache License, Version 2.0

Version 0.0.1

eventpy is currently usable and stable.

Source code

https://github.com/wqking/eventpy

Quick start

Install

pip install eventpy

Package

eventpy

Using CallbackList

# create a CallbackList
callbackList = CallbackList()
callbackList.append(lambda s, b : print("Got callback 1, s is %s b is %d" % (s, b)))
def anotherCallback(s, b) :
	print("Got callback 2, s is %s b is %d" % (s, b))
callbackList.append(anotherCallback)
# Invoke the callback list
callbackList("Hello world", True)

Using EventDispatcher

# create an EventDispatcher
dispatcher = EventDispatcher()

dispatcher.appendListener(3, lambda s, b : print("Got event 3, s is %s b is %d" % (s, b)))
dispatcher.appendListener(5, lambda s, b : print("Got event 5, s is %s b is %d" % (s, b)))
dispatcher.appendListener(5, lambda s, b : print("Got another event 5, s is %s b is %d" % (s, b)))

# Dispatch the events, the first argument is always the event type.
dispatcher.dispatch(3, "Hello", True)
dispatcher.dispatch(5, "World", False)

Using EventQueue

# create an EventQueue
queue = eventqueue.EventQueue()
queue.appendListener(3, lambda s, n : print("Got event 3, s is %s n is %d" % (s, n)))
queue.appendListener(5, lambda s, n : print("Got event 5, s is %s n is %d" % (s, n)))
queue.appendListener(5, lambda s, n : print("Got another event 5, s is %s n is %d" % (s, n)))

# Enqueue the events, the first argument is always the event type.
# The listeners are not triggered during enqueue.
queue.enqueue(3, "Hello", 38)
queue.enqueue(5, "World", 58)

# Process the event queue, dispatch all queued events.
queue.process();

Documentations

Run the unit tests

Go to the root folder of eventpy, run python -m pytest

eventpy's People

Contributors

wqking 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

Watchers

 avatar  avatar  avatar

eventpy's Issues

多线程策略bug

多线程策略失效 用的队列异步模式 但是多线程执行回调的时候只有第一次是多线程调度,然后后面的都是同步的了。。。还有个问题就是异步耗时回调时 目前这样效率太低了

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.