Closed GoogleCodeExporter closed 8 years ago
IMO, except for maybe Process.get_children(), all other process methods should
be quick enough to fit into any async loop "time window" without introducing
problematic slowdowns, therefore I see no need to use threads in the first
place.
Try this:
import time, os, psutil
t = time.time()
psutil.Process(os.getpid()).as_dict()
print time.time() - t
On my Linux box the code above took 0.0037 secs to complete.
If I add process children I get 0.0181 secs.
I expect that both 0.0037 and 0.0181 secs fit well in any async model.
Note that:
- as_dict() collects *all* process info, except its children.
- psutil's Linux implementation is already particularly slower compared to
other platform implementations. On other platforms the code above is likely to
run faster.
Original comment by g.rodola
on 27 Aug 2012 at 10:32
Thank you for your feedback. Linux is my top use case at the moment. I
have observed that the open call followed by read pauses the reactor,
albeit by a small amount for single calls, however delays can quickly back
up the reactor and impact time sensitive calls. I have an application
under development that needs to read a lot of the information that
psutil.Process exposes and then further process it (callback chains would
be very effective for this additional processing). Unfortunately I have
run into significant reactor blocking due to all the reads and post
processing that I need to perform with this application. This wrapper has,
in my case, alleviated the problem of blocking the reactor and thus the
application I am working on performs acceptably. I am only opening the
feature request as it may be useful for someone else using twisted with
psutil. As stated in my enhancement request, if the psutil project is ok
with the fact that I copied the test method from psutil.__init__ and the
psutil project is not interested in including this code in its source tree,
then I would like to send this code to the twisted project (MIT Licensed)
for possible inclusion in twisted.
Original comment by justin.v...@gmail.com
on 27 Aug 2012 at 3:51
Hi Justin,
I don't know your specific use case but spawning a thread for *every* operation
you do against the Process instance looks like a pretty inefficient approach to
me.
Assuming speed is actually a problem I would use a *single* thread to collect
all the process(es) info you need and use the twisted APIs to obtain/exchange
the return value(s) you need from that Process object (hint: consider using
Process.as_dict()).
I have nothing against you including parts of psutil source code as a patch for
another project (Twisted) so feel free to do it.
As for now I'm not interested in including your patch as-is but I'd like to
know what Twisted folks think about this, so in case you file an issue on their
tracker please let me know.
Closing out as rejected for now.
Original comment by g.rodola
on 27 Aug 2012 at 4:49
Thank you.
Justin Venus
Original comment by justin.v...@gmail.com
on 27 Aug 2012 at 5:03
Original issue reported on code.google.com by
justin.v...@gmail.com
on 27 Aug 2012 at 3:49