Skip to main content

Python Threads - from Dreadful to Threadful

Project description

Threaded Python

Threadful

Python Threads - from Dreadful to Threadful

Installation

pip install threadful

Usage

from threadful import thread

@thread # with or without ()
def some_function():
  time.sleep(10)
  return " done "

# when ready, it sill call these callback functions.
some_function().then(lambda result: result.strip().then(lambda result: print(result)) # prints: "done"

promise = some_function() # ThreadWithResult[str] object
promise.result() # Err(None)
time.sleep(15) # after the thread is done:
promise.result() # Ok(" done ")

# alternative to sleep:
result = promise.join() # " done " if success, raises if the thread raised an exception
@thread()
def raises() -> str:
  raises ValueError()


promise = raises().catch(lambda err: TypeError())

promise.join() # raises TypeError
promise.result() # Err(TypeError)


promise = raises().catch(lambda err: "Something went wrong")

promise.join()  # returns the string "Something went wrong"

License

threadful is distributed under the terms of the MIT license.

Changelog

See CHANGELOG.md

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

threadful-0.3.0.tar.gz (38.4 kB view details)

Uploaded Source

Built Distribution

threadful-0.3.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file threadful-0.3.0.tar.gz.

File metadata

  • Download URL: threadful-0.3.0.tar.gz
  • Upload date:
  • Size: 38.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.26.0

File hashes

Hashes for threadful-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f90be81f9f389f0db35a2cf1c5fbb8ecd5879f9573c6eb3d3e19ab3b9ac10699
MD5 7263f42d73a78debe25b75810d6545cd
BLAKE2b-256 3b216af16bc16cb260ee6372a49cff9551dfb24697ac0bee855b6c44bea22e34

See more details on using hashes here.

File details

Details for the file threadful-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: threadful-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.26.0

File hashes

Hashes for threadful-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 28dfd06f05abc74964048868b6571605485b7532ba09603cc107e3a06a7fce68
MD5 bae0802d23b782c98ad4897666824ca2
BLAKE2b-256 dff9aa39f06c83f6af2835a6ef2b1b764e346518c10b24acc8d1f695f8d77881

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