nikademus79 / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

Change some APIs in order to return an iterator instead of a list #243

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
As of right now we have different process methods which are returning a list:

Process.get_open_files()
Process.get_connections()
Process.get_children()
Process.get_threads()

I think *at least* the first 2 should return an iterator instead.
That would be particularly useful for get_open_files() and get_connections() 
since they can produce hundreds of results.
Users using those methods in a for loop won't suffer any code breakage.
Others will be bitten though, so maybe it makes sense to schedule this change 
for a major release (1.0.0 maybe, the project is mature enough to get there 
after all).

Original issue reported on code.google.com by g.rodola on 19 Jan 2012 at 1:47

GoogleCodeExporter commented 8 years ago
I don't fully agree. Not being able to index the return value of the methods 
would be annoying to me. I would then need to do

>>> [p for p in Process.get_children()][0]

instead of just

>>> Process.get_children()[0]

Original comment by dolfandr...@gmail.com on 19 Jan 2012 at 2:09

GoogleCodeExporter commented 8 years ago
Are you planning to change the underling C implementation for these methods? 
Right now the list is being built in C code, so there would be very little 
benefit to turning these into iterators at the Python API wrapper level.

Can we make a good enough case for a performance or functionality improvement 
by making these into iterators that it's worth breaking compatibility with the 
previous versions? 

Original comment by jlo...@gmail.com on 20 Jan 2012 at 8:35

GoogleCodeExporter commented 8 years ago
> Are you planning to change the underling C implementation for these methods?

Yes: 
http://docs.python.org/c-api/gen.html
Building the whole list in C and then yield-ify it in python would be useless.

> Can we make a good enough case for a performance or functionality improvement 
> by making these into iterators that it's worth breaking compatibility with 
> the previous versions? 

Yeah, I suppose it makes sense to make a benchmark first to figure out whether 
this actually worths the effort.

Original comment by g.rodola on 20 Jan 2012 at 8:45

GoogleCodeExporter commented 8 years ago
Thinking back, I think it's not worth the effort. Closing out.

Original comment by g.rodola on 24 Feb 2013 at 10:36