Skip to main content

Replacement for multiprocessing.Pool.

Project description

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.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

SteamFactory-0.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distributions

SteamFactory-0.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

SteamFactory-0.1-py2-none-any.whl (5.7 kB view details)

Uploaded Python 2

File details

Details for the file SteamFactory-0.1.tar.gz.

File metadata

  • Download URL: SteamFactory-0.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for SteamFactory-0.1.tar.gz
Algorithm Hash digest
SHA256 8c058c6eb59c01ae18dab48362c0d4b055995b5764318490f2acdb84a10795cd
MD5 3bef57fb142826ffcf5bbc32c92d2a5a
BLAKE2b-256 f30e25692f609584b073e52d40e376f857928dcc0f44e932ae98d770fc3c2fb6

See more details on using hashes here.

File details

Details for the file SteamFactory-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for SteamFactory-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 955d1eb83f132ac011a8495b9b920e4418f19eaf581ace904e48bbe167255234
MD5 37572e039607a44be11ffacf1050dd14
BLAKE2b-256 3cd71d36ed221cb0193ca2f5de000003510b7160fe52eea59b5b5b0d4f58a2b9

See more details on using hashes here.

File details

Details for the file SteamFactory-0.1-py2-none-any.whl.

File metadata

File hashes

Hashes for SteamFactory-0.1-py2-none-any.whl
Algorithm Hash digest
SHA256 6dd859e2038604a4394aa94b553c438a6cf3204a9ba98603cd3b2939283e19bc
MD5 d3158d0ed4d4c82c7994279e8951cff1
BLAKE2b-256 b79d5834f47a9be60fff01b22661f6ff2d5c3da110697041ecda334fdb7e4dd3

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