Skip to content

Instantly share code, notes, and snippets.

@urigoren
Last active February 3, 2022 09:51
Show Gist options
  • Save urigoren/5db3152aed17922c3087ed3cceb74dd9 to your computer and use it in GitHub Desktop.
Save urigoren/5db3152aed17922c3087ed3cceb74dd9 to your computer and use it in GitHub Desktop.
Run a python process in the background
from pathlib import Path
import subprocess, sys
def bgprocess(p:Path, *args):
python = sys.executable
if not isinstance(p, Path):
p = Path(p)
p = p.absolute()
return subprocess.Popen([python, p.name]+list(args), cwd = str(p.parent), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment