Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   multiprocessing and process run time (http://www.velocityreviews.com/forums/t688429-multiprocessing-and-process-run-time.html)

Thomas Robitaille 06-19-2009 02:40 PM

multiprocessing and process run time
 

Hi,

I'm making use of the multiprocessing module, and I was wondering if there
is an easy way to find out how long a given process has been running for.
For example, if I do

import multiprocessing as mp
import time

def time_waster():
time.sleep(1000)

p = mp.Process(target=time_waster)

p.start()

Is there a way that I can then find how long p has been running for? I
figured I can use p.pid to get the PID of the process, but I'm not sure
where to go from there. Is there an easy way to do this?

Thanks,

Thomas
--
View this message in context: http://www.nabble.com/multiprocessin...p24112854.html
Sent from the Python - python-list mailing list archive at Nabble.com.


OdarR 06-19-2009 03:24 PM

Re: multiprocessing and process run time
 
On 19 juin, 16:40, Thomas Robitaille <thomas.robitai...@gmail.com>
wrote:
> Hi,
>
> I'm making use of the multiprocessing module, and I was wondering if there
> is an easy way to find out how long a given process has been running for.
> For example, if I do
>
> import multiprocessing as mp
> import time
>
> def time_waster():
> * * time.sleep(1000)
>
> p = mp.Process(target=time_waster)
>
> p.start()
>
> Is there a way that I can then find how long p has been running for? I
> figured I can use p.pid to get the PID of the process, but I'm not sure
> where to go from there. Is there an easy way to do this?


Something like :

import multiprocessing as mp
import time

q_out = mp.Queue()

def time_waster(qo):
time.sleep(5)
qo.put('stopped at ' + time.ctime(time.time()))

def main():
p = mp.Process(target=time_waster, args=(q_out,))
print "start at: " + time.ctime(time.time())
p.start()
p.join()
print q_out.get()

if __name__ == "__main__":
main()


The Queue (the one from multiprocessing ! don't mix with the Queue
module) is used as a safe exchange object between the parent and all
the child.

Olivier

Piet van Oostrum 06-19-2009 08:03 PM

Re: multiprocessing and process run time
 
>>>>> Thomas Robitaille <thomas.robitaille@gmail.com> (TR) wrote:

>TR> Hi,


>TR> I'm making use of the multiprocessing module, and I was wondering if there
>TR> is an easy way to find out how long a given process has been running for.
>TR> For example, if I do


>TR> import multiprocessing as mp
>TR> import time


>TR> def time_waster():
>TR> time.sleep(1000)


>TR> p = mp.Process(target=time_waster)


>TR> p.start()


>TR> Is there a way that I can then find how long p has been running for? I
>TR> figured I can use p.pid to get the PID of the process, but I'm not sure
>TR> where to go from there. Is there an easy way to do this?


You could look at the psutil module: http://code.google.com/p/psutil/
--
Piet van Oostrum <piet@cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet@vanoostrum.org


All times are GMT. The time now is 07:13 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.