anypytools.jobpopen#

Adaapted from https://stackoverflow.com/a/56632466

This module provides a JobPopen class that is a subclass of the Popen class from the subprocess module.

Module Contents#

Classes#

JobPopen

Start a process in a new Win32 job object.

API#

class anypytools.jobpopen.JobPopen(*args, **kwargs)#

Bases: subprocess.Popen

Start a process in a new Win32 job object.

This subprocess.Popen subclass takes the same arguments as Popen and behaves the same way. In addition to that, created processes will be assigned to a new anonymous Win32 job object on startup, which will guarantee that the processes will be terminated by the OS as soon as either the Popen object, job object handle or parent Python process are closed.

Initialization

Start a new process using an anonymous job object. Takes the same arguments as Popen

class _winapijobhandler(oldapi, job)#

Bases: object

Patches the native CreateProcess function in the subprocess module to assign created threads to the given job

Initialization

__getattr__(key)#
CreateProcess(*args, **kwargs)#
_create_job_object()#

Create a new anonymous job object

_close_job_object(hjob)#

Close the handle to a job object, terminating all processes inside it

__exit__(exc_type, value, traceback)#
_Popen = None#
__del__()#