Skip to content

Instantly share code, notes, and snippets.

@moreati
Last active Nov 25, 2021
Embed
What would you like to do?
Demonstration of Lock instantiation spawning a subprocess
#!/usr/bin/env python3
import multiprocessing
import pprint
import sys
import psutil
print("Before", flush=True)
pprint.pprint([(p.pid, p.status(), ' '.join(p.cmdline())) for p in psutil.Process().children()])
lock = multiprocessing.Lock()
print("After", flush=True)
pprint.pprint([(p.pid, p.status(), ' '.join(p.cmdline())) for p in psutil.Process().children()])
@moreati

This comment has been minimized.

Copy link
Owner Author

@moreati moreati commented Nov 25, 2021

(v39) $ python --version
Python 3.9.8
(v39) $ python lockprocs.py
Before
[]
After
[(929,
  'running',
  '/opt/homebrew/Cellar/python@3.9/3.9.8/Frameworks/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python '
  '-c from multiprocessing.resource_tracker import main;main(4)')]
@moreati

This comment has been minimized.

Copy link
Owner Author

@moreati moreati commented Nov 25, 2021

(v310) $ python --version
Python 3.10.0
(v310) $ ./lockprocs.py       
Before
[]
After
[(1150,
  'running',
  '/opt/homebrew/Cellar/python@3.10/3.10.0_2/Frameworks/Python.framework/Versions/3.10/Resources/Python.app/Contents/MacOS/Python '
  '-c from multiprocessing.resource_tracker import main;main(4)')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment