On this page
multiprocessing.Process
Prev: multiprocessing.Pool | Up: multiprocessing | Next: multiprocessing.ProcessError
Rel: multiprocessing.active_children, multiprocessing.allow_connection_pickling, multiprocessing.Array, multiprocessing.AuthenticationError
Ref: docs.python.org — multiprocessing.Process
Tags: #public #python3 #stdlib #multiprocessing
Import
import multiprocessing
from multiprocessing import Process
Signature & Overview
multiprocessing.Process(group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None)
multiprocessing.Process class.
Methods & Attributes
Process.authkey(...)—Process.authkeymethod/property.Process.close(self)— Close the Process object.Process.daemon(...)— Return whether process is a daemonProcess.exitcode(...)— Return exit code of process orNoneif it has yet to stopProcess.ident(...)— Return identifier (PID) of process orNoneif it has yet to startProcess.interrupt(self)— Terminate process; sends SIGINT signalProcess.is_alive(self)— Return whether process is aliveProcess.join(self, timeout=None)— Wait until child process terminatesProcess.kill(self)— Terminate process; sends SIGKILL signal or uses TerminateProcess()Process.name(...)—Process.namemethod/property.Process.pid(...)— Return identifier (PID) of process orNoneif it has yet to startProcess.run(self)— Method to be run in sub-process; can be overridden in sub-classProcess.sentinel(...)— Return a file descriptor (Unix) or handle (Windows) suitable for waiting for process termination.Process.start(self)— Start child processProcess.terminate(self)— Terminate process; sends SIGTERM signal or uses TerminateProcess()
Usage
import multiprocessing as mp
# Spawns an independent Python process (guard with if __name__ == "__main__":):
p = mp.Process(target=print, args=("worker",), name="demo-worker")
assert p.name == "demo-worker" and not p.is_alive()
Gotchas
- Always call
p.join()(andp.close()when finished) so finished child processes don't linger as zombies. - On macOS and Windows (
spawn), child processes re-import your main module: Protect entry points withif __name__ == "__main__":.
REPL Inspect
from multiprocessing import Process
help(Process)
Linked from
Related notes
- tuts/python3/stdlib_module/multiprocessing/Pool Linked here; links to this page; shared tags: #multiprocessing, #stdlib
- tuts/python3/stdlib_module/multiprocessing/ProcessError Linked here; links to this page; shared tags: #multiprocessing, #stdlib
- tuts/python3/stdlib_module/multiprocessing Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/multiprocessing/active_children Linked here; shared tags: #multiprocessing, #stdlib
- tuts/python3/stdlib_module/multiprocessing/allow_connection_pickling Linked here; shared tags: #multiprocessing, #stdlib
- tuts/python3/stdlib_module/multiprocessing/Array Linked here; shared tags: #multiprocessing, #stdlib
- tuts/python3/stdlib_module/multiprocessing/AuthenticationError Linked here; shared tags: #multiprocessing, #stdlib
- tuts/python3/stdlib_module/multiprocessing/Barrier shared tags: #multiprocessing, #stdlib
- tuts/python3/stdlib_module/multiprocessing/BoundedSemaphore shared tags: #multiprocessing, #stdlib
- tuts/python3/stdlib_module/multiprocessing/BufferTooShort shared tags: #multiprocessing, #stdlib