Skip to main content

A multi-threaded event manager package for triggering methods in tandem groups

Project description

PyTandem

A multi-threaded event manager package for triggering methods in tandem groups.

Installation

Requirements

- python>=3.6

Install using PIP

python3 -m pip install --upgrade pytandem

Usage

First define the method(s) you would like to attach to the manager.

def print_num(num):
  print(num)

Then attach the method using the provided decorator - this will take an event name as a paramaneter. It should look like so:

from pytandem import pytandem

@pytandem.attach('event-name-here')
def print_num(num):
  print(num)

Whenever the above method (print_num()) is called, instead of being fired immediately it will be added to the manager threads to be started later on.

Next we can fire the method a few times:

for i in range(0, 3):
  print_num(i)

You'll notice nothing gets printed yet.

Now we can initiate the concurrent trigger of the 3 instances of the print_num() method we added to the threads earlier using the trigger() method - this, again, takes the event name as a parameter.

pytandem.trigger('event-name-here')

We can run the methods synchronously also by passing False in the threaded argument. This is set to True by default.

pytandem.trigger('event-name-here', threaded=False)

And lastly, we can also set the maximum number of concurrent threads that pytandem will use when triggering an event group. The default value for this is 4.

pytandem.trigger('event-name-here', max_threads=16)

Point to note: if max_threads is set to 4, and there are 20 methods attached on the same event name, then only 4 will run concurrently until one pops off the queue, essentially allowing the next in line to run. Methods will be fired according to the order in which they were first attached.

Note that a high max_threads value can cause out of memory issues if not careful.

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

pytandem-1.0.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytandem-1.0.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file pytandem-1.0.1.tar.gz.

File metadata

  • Download URL: pytandem-1.0.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.10 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.9

File hashes

Hashes for pytandem-1.0.1.tar.gz
Algorithm Hash digest
SHA256 866fb750023016fa3d4562a4399141875e38e296428b7f54896d7d2d9a70275c
MD5 d57aa87042901e5d8190931a71e60897
BLAKE2b-256 ee59aee93850c4aa2647cfa8cc7c004160dbdee59dced61d33a18cea5f99d112

See more details on using hashes here.

File details

Details for the file pytandem-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pytandem-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.10 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.9

File hashes

Hashes for pytandem-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aa8f07f56ba611f584f36ab61c760a8ed09e138db0fb0618b8cb4aa93d6f9d2c
MD5 004342368efb0c20679e7ac73f365213
BLAKE2b-256 882779d88e68e51c77fbf9a1b9cdacfb1514924135d7e1052a2654dbc5a02a01

See more details on using hashes here.

Supported by

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