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.1.1.tar.gz (36.2 kB view details)

Uploaded Source

Built Distribution

threadful-0.1.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for threadful-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9dd20fd0c77b246d338d7e56c144fa43c95078923eae0b02554a739c4a9be827
MD5 f2f210223ac9ce5f1bc068811fd8cac7
BLAKE2b-256 f71e3347cb303f382649ff9399861d3e3f33786d437d13652dee633ef56e741b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for threadful-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 df89fa3850890a2b0f43e9a66541ee7b5e42fc3c9a3f791d51b89be3c0299dbe
MD5 ce0b0c6a940c20b805b05a8bff639f23
BLAKE2b-256 ed78a5b1436932e9df6f9860397616a7604e18f208ed466ca94130c1e2cd2002

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