Skip to main content

Steam factory

Replacement for multiprocessing’s Pool, offering more powerful features. Allow running a generic Python function asynchronously.

Example usage

First, we are going to need a function that does something. In this case, it does nothing more than waiting one second.

import time

def do_nothing():
    time.sleep(1)
    print('Sleeping done')  # If you want some feedback..

To run this function in parallel, we’re going to need a Factory instance.

from steamfactory import Factory

# Create a factory, running up to 4 tasks concurrently
factory = Factory(size=4)

All set, we can schedule some async function executions:

for _ in range(4):
    factory.run(do_nothing)

After a second, you should see the four “Sleeping done” messages being printed at once.

In case you’re using this inside a script, and you need the main process to wait for all tasks to be executed before terminating (meaning that tasks will be lost), remember to call the shutdown() method:

factory.shutdown()

Getting feedback

How to get “feedback” from the tasks usually greatly depends on the application. Many times you don’t even bother with the function return value, you just need something to be done. Other times values might be large, or the required retention time might vary.

The library doesn’t currently offer any way to return results to the caller, but you can easily do something like this:

import time
from multiprocessing import Manager

from steamfactory import Factory

_mgr = Manager()
results = _mgr.dict()  # Shared between processes


def addup(a, b):
    time.sleep(1)
    results[(a, b)] = a + b

# Create a factory, running up to 4 tasks concurrently
factory = Factory(size=4)

# Let's schedule some tasks
factory.run(addup, 1, 2)
factory.run(addup, 3, 4)
factory.run(addup, 5, 6)
factory.run(addup, 7, 8)

factory.shutdown()

# Now, results contains all the results (after a 1s processing
# time)

Changelog

0.1

Initial release, implementing functionality to run functions asynchronously.

Metadata

Release files for SteamFactory 0.1

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

Source distribution (sdist)

Source distribution for SteamFactory 0.1
File Size Uploaded
SteamFactory-0.1.tar.gz 3.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for SteamFactory 0.1
File Interpreter ABI Platform
SteamFactory-0.1-py3-none-any.whl Python 3 none any Details
SteamFactory-0.1-py2-none-any.whl Python 2 none any Details

Total release size: 15.4 kB

Release files / SteamFactory-0.1.tar.gz

Download URL SteamFactory-0.1.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8c058c6eb59c01ae18dab48362c0d4b055995b5764318490f2acdb84a10795cd
BLAKE2b-256 checksum
How to use checksums
f30e25692f609584b073e52d40e376f857928dcc0f44e932ae98d770fc3c2fb6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / SteamFactory-0.1-py3-none-any.whl

Download URL SteamFactory-0.1-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
955d1eb83f132ac011a8495b9b920e4418f19eaf581ace904e48bbe167255234
BLAKE2b-256 checksum
How to use checksums
3cd71d36ed221cb0193ca2f5de000003510b7160fe52eea59b5b5b0d4f58a2b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / SteamFactory-0.1-py2-none-any.whl

Download URL SteamFactory-0.1-py2-none-any.whl
Size 5.7 kB
Tags Python 2
SHA-256 checksum
How to use checksums
6dd859e2038604a4394aa94b553c438a6cf3204a9ba98603cd3b2939283e19bc
BLAKE2b-256 checksum
How to use checksums
b79d5834f47a9be60fff01b22661f6ff2d5c3da110697041ecda334fdb7e4dd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1 This release

3 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