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

Uploaded Source

Built Distribution

threadful-0.2.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for threadful-0.2.1.tar.gz
Algorithm Hash digest
SHA256 0db4d0c3705dbc0d9a9ad8f78ed5fdb7c4808ba71734afc51ff6c61db13cfbd4
MD5 d30ef7ac025debe94741062c759d2eb3
BLAKE2b-256 1d8f7a7aa5e6bcddfa0fb6eba6ecf9f6a70d3f3ea2541db7135249fa17b5fa1c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for threadful-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ac6d2e121e15cb4e2e28a94480285c03848988925607d85dcc9cdd988f37f5a8
MD5 dd3541c7b830fa98a1a32ac720ff44fb
BLAKE2b-256 4b9db8c0e4c9fbb421d18e328894a3ef845750154fd97685ffba9317d6ea4c1f

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