Allows threads in Python to create “weak references” to themselves that detect when the thread is no longer running, similar to how a weak reference detects when its referent object is no longer alive.
Provides a lightweight way for one or more independent pieces of code to register per-thread cleanup callbacks without coordination.
Versioning
This library’s version numbers follow the SemVer 2.0.0 specification.
Installation
pip install threadref
Usage
import threadref
Create a reference to the current thread, with a callback that will fire when the thread exits:
reference = threadref.ref(lambda reference: ...)
Just like weakref.ref, threadref.ref instances must still be alive when their referent thread stops running, or their callback will not be called.
Create a finalizer for the current thread, which will be called when the thread exits:
finalizer = threadref.finalize(function, *args, **kwargs)
Just like weakref.finalize, threadref.finalize instances remain alive on their own as long as they need to, so this is a simpler and nicer interface in the typical case of registering cleanup functions.
Details
threadref.ref and threadref.finalize wrap weakref.ref and weakref.finalize, and the interface is the same except that they act as if they are referencing the thread itself instead of taking a referent argument, and internally they work by referencing an object saved on a private threading.local instance.
Metadata
Release files for threadref 1.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| threadref-1.1.5.tar.gz | 4.6 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| threadref-1.1.5-py38-none-any.whl | Python 3.8 | none | any | Details |
| threadref-1.1.5-py34-none-any.whl | Python 3.4 | none | any | Details |
| threadref-1.1.5-py2.py30-none-any.whl | Python 3.0, Python 2 | none | any | Details |
Total release size: 16.0 kB
Release files / threadref-1.1.5.tar.gz
| Download URL | threadref-1.1.5.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
58cb4ad64f1fb451a49e7997762d9a6f876c919ebf386f5ed415b7d6176f7e98
|
|
BLAKE2b-256 checksum How to use checksums |
e9acd43ba260fccf4d6d1804d350df9ebcfaa923625f82bf4076d3fbceef3637
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.2
|
Release files / threadref-1.1.5-py38-none-any.whl
| Download URL | threadref-1.1.5-py38-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3.8 |
|
SHA-256 checksum How to use checksums |
4035ff2e238caf7f26afb3aa21062a188601e2f4b3fd8992288a1630e723f398
|
|
BLAKE2b-256 checksum How to use checksums |
e22c87ffd6d94e226fe816908f1782b70fea6d0d808213615772d0604af9ee01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.2
|
Release files / threadref-1.1.5-py34-none-any.whl
| Download URL | threadref-1.1.5-py34-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3.4 |
|
SHA-256 checksum How to use checksums |
4be171125669908aea019fb3319cf16e55a136f700af8a231f81657b5da52745
|
|
BLAKE2b-256 checksum How to use checksums |
84fce19b5550c9c9464d142b8e94a1ed08298a0431b2f007347526f5ca30e6d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.2
|
Release files / threadref-1.1.5-py2.py30-none-any.whl
| Download URL | threadref-1.1.5-py2.py30-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 2 Python 3.0 |
|
SHA-256 checksum How to use checksums |
aae1865d189d7d3cc239ddac12648f17846654f958286b6f75c226b8f0d7903f
|
|
BLAKE2b-256 checksum How to use checksums |
261213a29911bcababcbf93d16a6e104370c2509a5330ccfbdad9eff85bdc381
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.2
|