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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for threadful-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b324bc754d1a632eb146d83516d1c003abf7e0375a53e2c9cd3418dc0e8d51cd
MD5 0c6de3cbb9460c88d071a37d49a101fa
BLAKE2b-256 c37014b68cc79f198d7bc99f4e297d9e723b444db3369de1dc391567c67462c4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: threadful-0.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6f7e886100124c763d430c708146d221ca31e0194d09ae6394db43fe73380053
MD5 60c8edd8ab9cf1c58b69410ac2e2fa82
BLAKE2b-256 7fa02ff6c9d8304615c57314492336e61d9e6234951e2ea36e5963cb6932afeb

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