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-0.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-0.0.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytandem-0.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.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.9

File hashes

Hashes for pytandem-0.0.1.tar.gz
Algorithm Hash digest
SHA256 d4c6fdb109883eb302b25790e5f15442ed30198e15465ca11afd3d10c9bdc536
MD5 6139ffaf96e82eda25a9089337223be6
BLAKE2b-256 312b5601b70926a615218298b7dda6865e41013ea0c30f229a4775f0d759703f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pytandem-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cf43241d6cfd5c91d0bb3c545f764e7bfc7d748eb26632a38ff3e07603d65299
MD5 dd3464e4ff744a76b28276996a8acaa6
BLAKE2b-256 9e0cd15fbaf69350261b670aa7f6327f1feb1deb5d7cbaf681ef1e275a62a299

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