Skip to main content

ThreadIO, is good for capture stdout at multi-thread environment.

>>> # standard capture
>>> from threadio import print_to_file
>>> with print_to_file(TextIO()) as fp:
...     print("hello world")
...
>>> fp.getvalue()
'hello world\n'
>>> # standard capture (but not stdout, stderr)
>>> from threadio import ThreadIO
>>> fp = ThreadIO(TextIO())
>>> with fp.capture(TextIO()) as fp2:
...     print("hello world", file=fp)
...     with fp.capture(TextIO()) as fp3:
...         print("hello world3", file=fp)
...         # not captured fp3, stored fp2
...         print("fail captured", file=fp2)
...
>>> fp.getvalue()
''
>>> fp2.getvalue()
'hello world\nfail captured\n'
>>> fp3.getvalue()
'hello world3\n'
>>> # thread example
>>> from threading import Thread
>>> from threadio import print_to_file
>>> th = Thread(target=print, args=("hello world!",))
>>> with print_to_file(TextIO()) as fp:
...     th.start()
...     th.join()
...     print("HAYO!")
...
hello world!
>>> fp.getvalue() # not capture other thread's print
'HAYO!\n'
>>> # note. print_to_xxx function change everything.
>>> a = sys.stdout
>>> with print_to_file(TextIO()): pass
>>> b = sys.stdout
>>> a is b
False

Metadata

Release files for threadio 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for threadio 0.1
File Size Uploaded Provenance Actions
threadio-0.1.tar.gz 2.2 kB Without provenance Details for threadio-0.1.tar.gz

Release files / threadio-0.1.tar.gz

Download URL threadio-0.1.tar.gz
Size 2.2 kB
Tags Source
SHA-256 checksum
How to use checksums
150ddac53b229611684956d5dd2e4893f220bea622e40b2a4c9a70e98102301c
BLAKE2b-256 checksum
How to use checksums
cde210e6d20761e127de0531331fccccd04a4e6c49e3bd3e03858ad76aee1fdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for threadio 0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page