Skip to main content

Threads with results

Project description

threadlet

PyPI - Version PyPI - Python Version

  • 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


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)

Uploaded Source

Built Distribution

threadlet-3.0.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

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

Hashes for threadlet-3.0.0.tar.gz
Algorithm Hash digest
SHA256 042e831917abd101e445b2ce19ef99c2dea7532b4e328ff75e5afd4117916ad4
MD5 0dfc9a6d0308ce318f9abb74ba17154e
BLAKE2b-256 bacdfc25d00e04fb10b7589d74e55e2bccaa3b5217192eb37d64a12f2014a93d

See more details on using hashes here.

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

Hashes for threadlet-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6ba9e8743cd80c33a2e03afcf956d58eaef0dfb4120144aa81b36371d128f21
MD5 18d9d72ecaf3a32264bf3d3b6df6fb7d
BLAKE2b-256 d237339c44e5994f7dbc3da607a7cedbe6f58ea422978d9afbe006e84253eec2

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