A context manager to fork.
Project description
Forking
Forking is a Python context manager that run the code in a different
process.
That means funny business:
>>> import os
>>> from forking import Forking
>>>
>>>
>>> with Forking():
... os._exit(0)
>>> print("I will survive!")
I will survive!
>>>
Obviously side effects are only executed in the child process so not visible to the parent:
>>> i = 1
>>> with Forking():
... i += 1
>>> print(i)
1
>>>
You can capture stdout and stderr though:
child = Forking()
with child:
print("Youpi")
print(child.stdout)
Note that we can't do with Forking() as child because the as child
part is not executed (as considered inside the with body).
You can also get info about the exit status of your process though
child.exit which contains code, signal and has_core_dump:
>>> child = Forking()
>>> with child:
... os._exit(12)
>>> print(child.exit.code)
12
>>>
Last trick, a Forking context can be reused (but its process will not):
>>> child = Forking()
>>> with child:
... os._exit(21)
>>> print(child.exit.code)
21
>>> with child:
... os._exit(22)
>>> print(child.exit.code)
22
>>>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file forking-0.1.tar.gz.
File metadata
- Download URL: forking-0.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5587d6ad2389c96f75a351de1cb2db7bab53c7c8c92cada8c62b2a6662e8ce0
|
|
| MD5 |
3e5cb714c89634223369a751ac2e1c25
|
|
| BLAKE2b-256 |
253513cc4d98e66fe4166291065eb83463b8eec78f8852a1abd763c1e408dfea
|
File details
Details for the file forking-0.1-py3-none-any.whl.
File metadata
- Download URL: forking-0.1-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0464e3072a704e6a70217db5e4b820ef0227be3351dff7c15b0ba499eb2839ba
|
|
| MD5 |
ec03f797f2a3100736725fabdad8add3
|
|
| BLAKE2b-256 |
29d8ac2fee611bbaf2145f9abd16536d66cdae639cc49b75e519db5e312b1e6f
|