Skip to main content

threading and communication/synchronisation conveniences

Project description

Release 20190812: bg: compute default name before wrapping func in @logexc.

Thread related convenience classes and functions.

Class AdjustableSemaphore

A semaphore whose value may be tuned after instantiation.

Function bg(func, daemon=None, name=None, no_start=False, no_logexc=False)

Dispatch the callable func in its own Thread; return the Thread.

Parameters:

  • func: callable to run in its own Thread.
  • daemon: optional argument specifying the .daemon attribute.
  • name: optional argument specifying the Thread name.
  • no_start: optional argument, default False. If true, do not start the Thread.
  • no_logexc: if false (default False), wrap func in @logexc.

Class LockableMixin

Trite mixin to control access to an object via its ._lock attribute. Exposes the ._lock as the property .lock. Presents a context manager interface for obtaining an object's lock.

Function locked(func)

A decorator for monitor functions that must run within a lock. Relies upon a ._lock attribute for locking.

Function locked_property(func, lock_name='_lock', prop_name=None, unset_object=None)

A thread safe property whose value is cached. The lock is taken if the value needs to computed.

Function via(cmanager, func, *a, **kw)

Return a callable that calls the supplied func inside a with statement using the context manager cmanager. This intended use case is aimed at deferred function calls.

Class WorkerThreadPool

MRO: cs.resources.MultiOpenMixin, cs.obj.O
A pool of worker threads to run functions.

Method WorkerThreadPool.__init__(self, name=None, max_spare=4)

Initialise the WorkerThreadPool.

Paramaters: name: optional name for the pool max_spare: maximum size of each idle pool (daemon and non-daemon)

Class WTPoolEntry

MRO: builtins.tuple
WTPoolEntry(thread, queue)

Release Log

Release 20190812: bg: compute default name before wrapping func in @logexc.

Release 20190729: bg: provide default name, run callable inside Pfx, add optional no_logexc=False param preventing @logec wrapper if true.

Release 20190422: bg(): new optional no_start=False keyword argument, preventing Thread.start if true

Release 20190102: Drop some unused classes. New LockableMixin, presenting a context manager and a .lock property.

Release 20160828: Use "install_requires" instead of "requires" in DISTINFO.

Release 20160827: Replace bare "excepts" with "except BaseException". Doc updates. Other minor improvements.

Release 20150115: First PyPI release.

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

cs.threads-20190812.tar.gz (6.1 kB view details)

Uploaded Source

File details

Details for the file cs.threads-20190812.tar.gz.

File metadata

  • Download URL: cs.threads-20190812.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.4

File hashes

Hashes for cs.threads-20190812.tar.gz
Algorithm Hash digest
SHA256 c606eed63a585d2c3e31ceef865d00dd2cbdb071acd01e1222d8b7a0c89365b7
MD5 91cac9461e7e75e4d2d3c2d07dff3309
BLAKE2b-256 d84d7b9e21fb6c0efae75e98a4a1b8580bc1a8f8c0ee9c245002f37f2555aae5

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