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

get_children run slow under windows7 #415

Closed
giampaolo opened this issue May 23, 2014 · 5 comments
Closed

get_children run slow under windows7 #415

giampaolo opened this issue May 23, 2014 · 5 comments

Comments

@giampaolo
Copy link
Owner

From lisongm...@gmail.com on August 03, 2013 14:08:37

What steps will reproduce the problem?  
1. running python -m cProfile aa.py , with content:
#!/usr/bin/env python
# -*- coding=utf-8 -*-

import os
import psutil
from subprocess import Popen

p = Popen(['python', 'test/pyha/sleep.py'])
parent = psutil.Process(os.getpid())
childs = parent.get_children(recursive=True)
print childs
p.wait()

2. the resoult is  
       82    0.001    0.000    6.569    0.080 __init__.py:269(ppid)
        1    0.000    0.000    0.106    0.106 __init__.py:286(name)
       83    0.000    0.000    0.645    0.008 __init__.py:389(create_time)
        1    0.001    0.001    7.262    7.262 __init__.py:496(get_children)
3. get ppid cost 6s with 82 times, it is so slow. 

What is the expected output?  
get_children should return quickly. 

What do you see instead?  
get all pid's ppid in one system call rather than per pid. 

What version of psutil are you using? What Python version?  
python 2.7.2
psutil 1.0.1 

On what operating system? Is it 32bit or 64bit version?  
windows7 amd64 Please provide any additional information below.

Original issue: http://code.google.com/p/psutil/issues/detail?id=415

@giampaolo
Copy link
Owner Author

From g.rodola on August 06, 2013 07:16:44

I see no obvious way to speed this up as you're forced to retrieve ppid for all 
processes no matter what.

As for your suggestion: except perhaps for Windows (I should double check) 
there's no operating system providing a system call to retrieve all pid's ppid 
in one shot: you're forced to iterate over all processes.

@giampaolo
Copy link
Owner Author

From g.rodola on August 25, 2013 15:56:21

I'm going to close this out as invalid.

Status: Invalid

@giampaolo
Copy link
Owner Author

From g.rodola on September 07, 2013 05:33:53

>> get all pid's ppid in one system call rather than per pid.
> you're forced to retrieve ppid for all processes no matter what.

It turns out retrieving all parent pids in one call on Windows it was possible 
after all.  I just didn't remember how ppid() was implemented on Windows.
get_children() is now an order of magnitude faster (+20x or something like that).
Committed in revision 32ca76279dce .

Status: FixedInHG
Labels: -Type-Defect -OpSys-Windows7 Type-Enhancement OpSys-Windows
Milestone-1.1.0

@giampaolo
Copy link
Owner Author

From g.rodola on September 28, 2013 03:06:18

Status: Fixed

@giampaolo
Copy link
Owner Author

From g.rodola on September 28, 2013 10:32:46

Closing out as fixed. Release 1.1.0 is now available for download.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant