Skip to main content

Quick and simple multithreading

Reason this release was yanked:

fixed fatal go_cluster bug

Project description

Ready Thready Go

Ready Thready Go (rtgo) is a Python module for easily running Python functions utilising multi-threading.

Installation

Ready Thready Go is available through PyPI as rtgo. It can be installed via pip:

pip install rtgo

Requirements

No additional packages are required to run Ready Thready Go.

Python 3.6 or higher is recommended.

Usage

To use Ready Thready Go, the module ReadyThready should first be imported from the rtgo package.

The ReadyThready function 'go' is used to run a function with multiple different input arguments over multiple threads.

ReadyThready.go takes the arguments:

  • func, the name of the function to be run
  • args, a list of arguments to be passed to the function, including a list of multiple different arguments
  • arg_data_index, the position of the list of multiple arguments within the args list
  • n_threads, the number of threads to be used

It may be helpful to think of ReadyThready.go as an alternative to using a for loop to pass arguments from a list to a function: instead of

def my_function(number):
    new_number = (number * 3) - 1 
    return new_number

my_list = [1,2,3,4,5]

for x in my_list:
    my_function(x)

It is possible to supply the list and the function to ReadyThready.go and have it run in parallel over a specified number of threads:

from rtgo import ReadyThready
def my_function(number):
    new_number = (number * 3) - 1 
    return new_number

my_list = [1,2,3,4,5]

ReadyThready.go(func=my_function, args=[my_list], arg_data_index = 0, n_threads = 4)

Examples

Divide data and process a function on multiple threads

from rtgo import ReadyThready

# initialise variables
my_input_list = [1,2,3,4,5,6,7,8]
example_string = "example:"

# define a function to be run over multiple threads
def my_example_func(number, phrase):
    if number < 5:
        print(f"{phrase} {number} is less than 5")

# run the function over 4 threads
ReadyThready.go(func=my_example_func, args=[my_input_list, example_string], arg_data_index=0, n_threads=4)

Execute multiple functions concurrently

from rtgo import ReadyThready
import requests

# Retrieve Human Phenotype Ontology data
def get_hpo_data():
    my_hpo_data = requests.get("http://hpo.jax.org/api/hpo/term/HP%3A0001166/genes")
    my_hpo_data = my_lengthy_processing(my_hpo_data)
    return my_hpo_data

# Retrieve Medical Subject Headings data
def get_mesh_data():
    my_mesh_data = requests.get("https://id.nlm.nih.gov/mesh/lookup/term?label=obesity&match=contains&limit=10")
    my_mesh_data = my_lenghty_processing(my_mesh_data)
    return my_mesh_data

# run each function on a separate thread
ontology_data = ReadyThready.go_cluster([get_hpo_data, get_mesh_Data])

Using your project's logger

from rtgo import ReadyThready
import logging 

# create a logger for your project 
my_project_logger = logging.getLogger('example')
my_project_logger.setLevel(logging.INFO)
my_project_logger.addHandler(logging.StreamHandler())

# initialise variables
my_input_list = [1,2,3,4,5,6,7,8]
example_string = "example:"

# a simple function
def my_example_func(number, phrase):
    if number < 5:
        print(f"{phrase} {number} is less than 5")

# set ReadyThready to use your project logger
ReadyThready.set_logger(my_project_logger)

# run the function over 8 threads
ReadyThready.go(func=my_example_func, args=[my_input_list, example_string], arg_data_index=0, n_threads=8)

Authors

Thomas Rowlands, Emma Croot

Licence

GNU (see LICENCE.txt)

Change log

###version 0.0.5:

First stable version

###version 0.0.6: Improved error handling and logging

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

rtgo-0.0.6.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

rtgo-0.0.6-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file rtgo-0.0.6.tar.gz.

File metadata

  • Download URL: rtgo-0.0.6.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5

File hashes

Hashes for rtgo-0.0.6.tar.gz
Algorithm Hash digest
SHA256 238de82fad95663d7e1101eb87e1d447748af1977c82a80fc699488c1c94a110
MD5 c5a62d4cd4d71c3e7f8ba4d33cfa3239
BLAKE2b-256 449750b18415fe551b7a5e4058cc88b96c84ce0517240dc1abab4e47fef49c44

See more details on using hashes here.

File details

Details for the file rtgo-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: rtgo-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5

File hashes

Hashes for rtgo-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 7176391fd396920c4fa186dd9be44033b203988607e92939256ca4fc94e78e7f
MD5 15266da5bec888d26bc4317ae100b32a
BLAKE2b-256 4127b39290e4e6e9fafac218a1460bd91a1c3c24466f93c47ff5fceaed462a1b

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