Threads with results
Project description
threadlet
- Task is an object for containing a function and a
Future
object to store a result of the function. - Worker is a thread with a loop over incoming tasks.
- SimpleThreadPoolExecutor is a more efficient variant of the
concurrent.futures.ThreadPoolExecutor
which spawns all the threads at the beginning.
Table of Contents
Installation
pip install threadlet
License
threadlet
is distributed under the terms of the MIT license.
Usage
from threadlet import Task, Worker, SimpleThreadPoolExecutor
def calc(x):
return x * 2
# run task asynchronously in a separate thread
future = Task(calc, 2).start()
assert future.result() == 4
# spawns one thread to sequentially handle all submitted functions
with Worker() as w:
f1 = w.submit(calc, 3)
f2 = w.submit(calc, 4)
assert f1.result() == 6
assert f2.result() == 8
# spawns 4 threads to handle all tasks in parallel
with SimpleThreadPoolExecutor(4) as tpe:
future = tpe.submit(calc, 5)
assert future.result() == 10
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
threadlet-3.0.0.tar.gz
(5.7 kB
view details)
Built Distribution
File details
Details for the file threadlet-3.0.0.tar.gz
.
File metadata
- Download URL: threadlet-3.0.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 042e831917abd101e445b2ce19ef99c2dea7532b4e328ff75e5afd4117916ad4 |
|
MD5 | 0dfc9a6d0308ce318f9abb74ba17154e |
|
BLAKE2b-256 | bacdfc25d00e04fb10b7589d74e55e2bccaa3b5217192eb37d64a12f2014a93d |
File details
Details for the file threadlet-3.0.0-py3-none-any.whl
.
File metadata
- Download URL: threadlet-3.0.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6ba9e8743cd80c33a2e03afcf956d58eaef0dfb4120144aa81b36371d128f21 |
|
MD5 | 18d9d72ecaf3a32264bf3d3b6df6fb7d |
|
BLAKE2b-256 | d237339c44e5994f7dbc3da607a7cedbe6f58ea422978d9afbe006e84253eec2 |