Skip to main content

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

Release files for rtgo 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rtgo 0.0.7
File Size Uploaded
rtgo-0.0.7.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rtgo 0.0.7
File Interpreter ABI Platform
rtgo-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 23.4 kB

Release files / rtgo-0.0.7.tar.gz

Download URL rtgo-0.0.7.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1a668c966d7b0033188ff99b621da2e15494fe16b29f529a286c7a53f92ceb5a
BLAKE2b-256 checksum
How to use checksums
74750500ae95ad260ffc6ab0dd971403d80ef01674485b773998f9f99d5ecc7e
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / rtgo-0.0.7-py3-none-any.whl

Download URL rtgo-0.0.7-py3-none-any.whl
Size 18.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24c7c3c67ce8450147586b74cf4c631515ecf4b51f4c50d365d30b77e04b93f4
BLAKE2b-256 checksum
How to use checksums
757043092867e56cc55bd866fd7c37c2a03ec1e7860186769164f89df3d04f93
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.4

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page