get how much time python subprocess spends

后端 未结 3 1725
一整个雨季
一整个雨季 2021-02-19 01:04

I\'d like to time how long does the subprocess take. I tried to use

start = time.time()
subprocess.call(\'....\')
elapsed = (time.time() - start)
3条回答
  •  遇见更好的自我
    2021-02-19 01:21

    It depends on which time you want; elapsed time, user mode, system mode?

    With resource.getrusage you can query the user mode and system mode time of the current process's children. This only works on UNIX platforms (like e.g. Linux, BSD and OS X):

    import resource
    info = resource.getrusage(resource.RUSAGE_CHILDREN)
    

    On Windows you'll probably have to use ctypes to get equivalent information from the WIN32 API.

提交回复
热议问题