Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are the timestamps incorrect when debugging App Engine Python code

Under my debugger:

logging.info("TZ = %s -- It is now: %s", os.environ['TZ'], time.ctime())
TZ = UTC -- It is now: Mon Oct 17 12:10:44 2011

Under App Engine Launcher:

logging.info("TZ = %s -- It is now: %s", os.environ['TZ'], time.ctime())
TZ = UTC -- It is now: Mon Oct 17 17:09:24 2011

So what do I have setup wrong? This affects not just time.ctime(), but all the data dropped into the debug database. I'd like the debugger to run in the same "timeframe" as the app engine launcher because of timestamps in the database, and the debugger is slower than the launcher, so I don't want to use it all the time.

like image 553
boatcoder Avatar asked Oct 17 '11 17:10

boatcoder


1 Answers

The issue is that the C runtime functions on Windows with Python 2.5 seem to cache the value of the TZ environment variable the first time either time or ctime is called. The following will display the time in local time and not in UTC:

import time, os
time.time()
os.environ['TZ'] = 'UTC'
print time.ctime()

Wing's debugger calls time() before running any AppEngine code so the initial value of TZ was captured. The workaround is to set TZ=UTC in the environment variables via the project properties dialog.

like image 75
John Ehresman Avatar answered Oct 12 '22 08:10

John Ehresman