Skip to content

agalera/basicevents

Repository files navigation

pythonversions Code Climate Codecov Travis License

BasicEvents

python basic events send non-blocking

Install

pip install basicevents

Link pypi: https://pypi.python.org/pypi/basicevents

Example

# recommeded check all examples
from basicevents import (subscribe, send_thread, send_queue,
                         send_blocking, add_subscribe, send, run)

@subscribe("pepito")
def example(*args, **kwargs):
    print "recv signal, values:", args, kwargs

def example2(*args, **kwargs):
    print "manual subscribe"

# manual subscribe
add_subscribe("pepito", example2)

# add to queue signals (non-blocking)
send("pepito", 1, 2, 3, example="added queue")

# add to queue signals (non-blocking)
send_queue("pepito", 1, 2, 3, example="added queue")

# create new thread for this request (non-blocking)
send_thread("pepito", 1, 2, 3, example="new thread")

# This is blocking
send_blocking("pepito", 1, 2, 3, example="blocking")

run()
send("STOP")

Documentation

Functions

@subscribe(name_event) With this decorator you can subscribe to all events that are sent to name_event.

manual subscribe add_subscribe(name_event, function)

  • added in queue (non-blocking)

send_queue(name_event, *args, **kwargs)

  • run in new thread (non-blocking)

send_thread(name_event, *args, **kwargs)

  • run blocking (blocking)

send_blocking(name_event, *args, **kwargs)

  • Note: Currently running in individual process.

Attributes events

  • events.subs

return:

{'juanito': [<function __main__.example2>],
 'pepito': [<function __main__.example>]}
  • events.queue

return queue

queue is processed automatically and do not need to access this attribute, but if you want you can use https://docs.python.org/2/library/queue.html

  • events.timeout

return int

  • events.logger

return function

You can change the function that is executed when an exception occurs. Uses default print You can modify it if you wish.

from basicevents import events
events.logger = function
  • events.send

return function

You can change the function send (It is a link). default is events.send_queue

from basicevents import events
events.send = events.send_blocking # or other functions
  • these parameters are too, have documented above:
add_subscribe, send, send_queue, send_thread, send_blocking

About

python basic events non-blocking

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages