Detach
Fork and detach the current process.
Usage
The detach package contains a context manager called Detach. It is used
with with statement to fork the current process and execute code in that
process. The child process exits when the context manager exits. The following
parameters may be passed to Detach to change its behavior:
stdout- Redirect child stdout to this stream.stderr- Redirect child stderr to this stream.stdin- Redirect his stream to child stdin.close_fds- Close all file descriptors in the child excluding stdio.exclude_fds- Do not close these file descriptors if close_fds isTrue.daemonize- Exit the parent process when the context manager exits.
Examples
Simple Fork with STDOUT
import detach, os, sys
with detach.Detach(sys.stdout) as d:
if d.pid:
print("forked child with pid {}".format(d.pid))
else:
print("hello from child process {}".format(os.getpid()))
Daemonize
import detach
from your_app import main
def main():
"""Your daemon code here."""
with detach.Detach(daemonize=True) as d:
if d.pid:
print("started process {} in background".format(pid))
else:
main()
Call External Command
import detach, sys
pid = detach.call(['bash', '-c', 'echo "my pid is $$"'], stdout=sys.stdout)
print("running external command {}".format(pid))
License
Copyright (c) 2014 Ryan Bourgeois. This project and all of its contents is licensed under the BSD-derived license as found in the included LICENSE file.
Metadata
Release files for detach3k 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| detach3k-1.0.0.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| detach3k-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.0 kB
Release files / detach3k-1.0.0.tar.gz
| Download URL | detach3k-1.0.0.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0fbeacd7fc59b85f82dcb952bccafa483a22b5097d67e36f36682ad07931855b
|
|
BLAKE2b-256 checksum How to use checksums |
faaf4a11418cb8b0dca5172a141a797da79aa89bf9cf4264175edd2cc161319d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.7.9 Darwin/19.6.0
|
Release files / detach3k-1.0.0-py3-none-any.whl
| Download URL | detach3k-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
83f58e86af1718595e8970084f33676fd097751ca9b8312f90d3e76210601ac3
|
|
BLAKE2b-256 checksum How to use checksums |
e0e0886ae0d3e6e3929c4643a66d1bd7b522771e72f3ebd7f4ac0fc2db37fc52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.7.9 Darwin/19.6.0
|