Skip to main content

An event system build on top of the concurrent futures library, including additional threading tools

Project description

ConcurrentEvents

.. image:: https://gitlab.com/Reggles44/concurrentevents/badges/master/pipeline.svg :alt: pipeline status :target: https://gitlab.com/Reggles44/concurrentevents/-/commits/master

.. image:: https://gitlab.com/Reggles44/concurrentevents/badges/master/coverage.svg :alt: coverage report :target: https://gitlab.com/Reggles44/concurrentevents/-/commits/master

.. image:: https://readthedocs.org/projects/concurrentevents/badge/?version=latest :target: https://concurrentevents.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status

ConcurrentEvents is a light weight event system and threading tools build around the concurrent futures library.

The aim of this project is to create an extremely simple and generic event system as well as tools to monitor and use it effectively.

The focus of this project is based around the ConcurrentEvents.EventManager, ConcurrentEvents.EventHandler, ConcurrentEvents.Event classes and ConcurrentEvents.Catch decorator to create a simple and safe way to do multi-threading through an event framework.

Installation

ConcurrentEvents should be installed through pip on python3.5 or higher

.. code-block:: bash

python -m pip install ConcurrentEvents

Usage

ConcurrentEvents is used similar to other event systems where by decorators are used to map functions to events. This simple example shows a hello world run through the event system but catching the Start event

.. code-block:: python

from ConcurrentEvents import EventManager, catch, Start

@catch(Start)
def hello_world():
    print("Hello World")

EventManager().start()

A more complicated example might involve having one event trigger more. In the following example a custom Event is created to handle outputting counting. Additionally the CountingEventHandler class is made as a subclass of EventHandler so that it can use the build in functionality of firing and canceling events.

.. code-block:: python

from ConcurrentEvents import EventManager, EventHandler, catch, Start, Event

class CountEvent(Event):
    pass

class CountingEventHandler(EventHandler):
    @catch(Start)
    def start_counting(self):
        for i in range(10):
            self.fire(CountEvent(i))

    @catch(CountEvent)
    def print_count(self, i):
        print(i)

EventManager().start()

Using the same example of counting there is also functionality to cancel an event or simply trigger exit. The following code will cancel when i is equal to 5. At the same time, if i is equal to 8 the exit event will fire which stops all functionality and goes to cleanup.

.. code-block:: python

from ConcurrentEvents import EventManager, EventHandler, catch, Start, Event, Exit

class CountEvent(Event):
    pass

class CountingEventHandler(EventHandler):
    @catch(Start)
    def start_counting(self):
        for i in range(10):
            self.fire(CountEvent(i))
            if i == 5:
                self.cancel()
            if i == 8:
                self.fire(Exit())

    @catch(CountEvent)
    def print_count(self, i):
        print(i)

EventManager().start()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ConcurrentEvents-1.12.5.tar.gz (7.1 kB view details)

Uploaded Source

File details

Details for the file ConcurrentEvents-1.12.5.tar.gz.

File metadata

  • Download URL: ConcurrentEvents-1.12.5.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9

File hashes

Hashes for ConcurrentEvents-1.12.5.tar.gz
Algorithm Hash digest
SHA256 6747ca59b9b88bf1ac975cb3d0d6fc83147a356549aa90b3c8ff2b0107d7395e
MD5 aa62ed44d07ed62f88c47775f4a7470a
BLAKE2b-256 c2c31bef7d4effb1b1057b5700ad541041f247c6c88697f5dd6d3fa56cbff054

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page