ID EN
Multiprocessing

Process

Python 3.11

Process objects represent activity that is run in a separate process. The Process class has equivalents of all the methods of threading.Thread.

Syntax

PYTHON
class multiprocessing.Process(group=None, target=None, name=None, args=(), kwargs={}, *, daemon=None)

Examples

Example 1
PYTHON
>>> from multiprocessing import Process
>>> p = Process(target=print, args=[1])
>>> p.run()
1
>>> p = Process(target=print, args=(1,))
>>> p.run()
1
Example 2
PYTHON
>>> import multiprocessing, time, signal
>>> p = multiprocessing.Process(target=time.sleep, args=(1000,))
>>> print(p, p.is_alive())
<Process ... initial> False
>>> p.start()
>>> print(p, p.is_alive())
<Process ... started> True
>>> p.terminate()
>>> time.sleep(0.1)
>>> print(p, p.is_alive())
<Process ... stopped exitcode=-SIGTERM> False
>>> p.exitcode == -signal.SIGTERM
True

See Also

Process threading.Thread threading.Thread run() name daemon run() Process