0

I have a python module whose responsibility is to interpolate timestamp. I have a use case where I want to get process start time whenever a function in this module is called.

In Perl equivalent of this module, I used $^BASETIME, $^T to get the process start time. Is there a similar way in python also?

I referred to this question (How to retrieve the process start time (or uptime) in python). Is there any other way except using ps?

import time

def get_process_start_time():
    return time.time()

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Deepanshu Arora
  • 375
  • 1
  • 5
  • 21
  • The process is still identical to the answers in the question you linked: [How to retrieve the process start time (or uptime) in python](https://stackoverflow.com/questions/2598145/how-to-retrieve-the-process-start-time-or-uptime-in-python). None of them require you to isolate the start time to a particular module. – jpmc26 Mar 28 '19 at 08:00
  • The intent behind this question is to check if we have perl special variables support in python – Deepanshu Arora Mar 28 '19 at 08:13

1 Answers1

0

Upon more deeper investigation, I found that I can use 'create_time' method of Process to get start time of process anywhere in the code.

import os
import psutil

psutil.Process(os.getpid()).create_time()

Deepanshu Arora
  • 375
  • 1
  • 5
  • 21