Intuitive parallel map calls for Python
Project description
Ultima - intuitive parallel map() for Python
What is it?
ultima is a Python package that provides a simple yet powerful interface to do map() in parallel.
It uses concurrent.futures as its execution backend and can run tasks in either threads or sub-processes.
It is designed to squeeze maximum performance (let those CPUs burn 🔥) with the same simple interface.
Usage examples:
Run a heavy function in sub-processes:
from ultima import Workforce
inputs = open("input_data.txt")
with Workforce() as wf:
for result in wf.map(cpu_intensive_function, inputs):
...
An equivalent one-liner:
from ultima import ultimap
for result in ultimap(cpu_intensive_function, inputs):
...
The default backend is multiprocessing, but you can easily use threads instead:
from ultima import ultimap
for result in ultimap(io_bound_function, inputs, backend='threading', n_workers=64):
...
To chain an IO-intensive task with a CPU-intensive task:
from ultima import ultimap
def io_intensive(url):
import requests
return requests.get(url).text
def cpu_intensive(page):
import hashlib
return hashlib.sha1(page.encode()).hexdigest()
urls = open("urls.txt")
webpages = ultimap(io_intensive, urls, backend='threading', n_workers=64)
hashes = ultimap(cpu_intensive, webpages, backend='multiprocessing')
print(len(set(hashes)))
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
ultima-1.0.3.zip
(65.4 kB
view details)
File details
Details for the file ultima-1.0.3.zip.
File metadata
- Download URL: ultima-1.0.3.zip
- Upload date:
- Size: 65.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c7cbc21f9e89dae9859334fc3485a79aaeae6ac0eb32957dba991a1330c7968
|
|
| MD5 |
865b031a9d41db97707ee03688f80b7e
|
|
| BLAKE2b-256 |
ca24ad193d03e064b4a61c1e2b37b61fd7e33f9635ead6aedaad17bee1fbf775
|