First of all, I encountered the pit, the production of problems encountered, I dispatched the Python script to execute and monitor this process, the Python script run much longer than the Python script in its own statistical execution time.
The time to monitor the execution of a Python script is 36 hours , while the Python script counts itself for about 4 hours .
The first thing that comes to mind after a problem is that Linux is out of the question, looking for a variety of logs that do not find anything unusual.
Then I think of the Py2neo write data that is used in Python to block the execution of the process.
Finally, the problem is found: the way Python scripts use statistical time is Time.clock (), which counts the CPU execution time, not the execution time of the program.
Next, compare the statistical times of several Python ways: Method 1:
Import datetime
StartTime = Datetime.datetime.now ()
#long running
#do something other
endtime = Datetime.datetime.now ()
print (endtime-starttime). seconds
Datetime.datetime.now () Gets the current date, which, after the execution of the program, obtains the time value of the program execution . Method 2:
Start = Time.time ()
#long running
#do something other end
= Time.time ()
print End-start
Time.time () Gets the current time (in seconds) since the era. If the system clock provides them, there may be fractions of seconds. So this place returns a floating-point type. This also gets the execution time of the program . Method 3:
Start = Time.clock ()
#long running
#do something other end
= Time.clock ()
print End-start
Time.clock () returns the CPU time since the start of the program or the first time the clock () is invoked. This has as much precision as the system record. The return is also a floating-point type. The CPU execution time is obtained here.
Note: Program execution time =CPU time + IO time + hibernate or wait time