File: daemonize.py

package info (click to toggle)
hg-git 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,244 kB
  • sloc: python: 8,702; sh: 185; makefile: 23
file content (20 lines) | stat: -rwxr-xr-x 399 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python3
#
# Call another command and save its pid
#

import os
import subprocess
import sys

with open(sys.argv[1], "xb") as outf:
    proc = subprocess.Popen(
        [sys.executable] + sys.argv[2:],
        stdout=outf,
        stderr=outf,
        close_fds=True,
        start_new_session=True,
    )

with open(os.getenv("DAEMON_PIDS"), "a") as fp:
    fp.write(f"{proc.pid}\n")