Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psutil.process_iter() raise TypeError (it's not thread safe) #1991

Closed
giampaolo opened this issue Oct 2, 2021 · 0 comments
Closed

psutil.process_iter() raise TypeError (it's not thread safe) #1991

giampaolo opened this issue Oct 2, 2021 · 0 comments
Labels

Comments

@giampaolo
Copy link
Owner

To reproduce:

import psutil, threading, traceback

def worker():
    try:
        for p in psutil.process_iter():
            with p.oneshot():
                p.cpu_times()
    except Exception as err:
        with lock:
            traceback.print_exc()

lock = threading.Lock()
for x in range(1000):
    t = threading.Thread(target=worker)
    t.start()

...prints:

Traceback (most recent call last):
  File "foo.py", line 56, in worker
    for p in psutil.process_iter():
  File "/home/giampaolo/svn/psutil/psutil/__init__.py", line 1434, in process_iter
    ls = sorted(list(_pmap.items()) +
TypeError: '<' not supported between instances of 'NoneType' and 'Process'
Traceback (most recent call last):
  File "foo.py", line 56, in worker
    for p in psutil.process_iter():
  File "/home/giampaolo/svn/psutil/psutil/__init__.py", line 1434, in process_iter
    ls = sorted(list(_pmap.items()) +
TypeError: '<' not supported between instances of 'NoneType' and 'Process'
Traceback (most recent call last):
  File "foo.py", line 56, in worker
    for p in psutil.process_iter():
  File "/home/giampaolo/svn/psutil/psutil/__init__.py", line 1434, in process_iter
    ls = sorted(list(_pmap.items()) +
...
@giampaolo giampaolo added the bug label Oct 2, 2021
@giampaolo giampaolo changed the title psutil.process_iter() is not thread safe psutil.process_iter() raise TypeError (it's not thread safe) Oct 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant