OK, horrible workaround deployed. Roughly:
PATHS=[...
(r'/_ah/warmup', WarmupView),
(r'/_ah/start', StartView),
class WarmupView(webapp.RequestHandler):
def get(self, *args): # pylint:disable=W0613,R0201
base.SERVER_TZ = None # allow base.set_now() to reset server timezone
class StartView(webapp.RequestHandler):
def get(self, *args): # pylint:disable=W0613,R0201
base.SERVER_TZ = None # allow base.set_now() to reset server timezone
base.now()
base.py:
import pytz
...
SERVER_TZ = None
...
def now(nowval=None):
global SERVER_TZ
...
if SERVER_TZ is None:
try:
# HACK of the year award! os.environ['TZ'] isn't available during GAE/Managed VMs startup
# and date +%Z and /etc/timezone didn't have useful information either
# even env | grep TZ failed!!
import subprocess
localtz = subprocess.check_output("date +%Z", shell=True).strip()
# SUPER HACK: I couldn't find pytz-compatible timezone strings, so I hacked it.
# Yes, I know I'm going to hell for this.
SERVER_TZ = 'America/Chicago' if localtz == 'CST' else 'UTC'
except:
SERVER_TZ = 'UTC'
nowval = datetime.datetime.now() # pylint:disable=W9914
if SERVER_TZ != 'UTC':
# set the tz to the server tz, convert to UTC, then strip the tz info
nowval = nowval.replace(tzinfo=pytz.timezone(SERVER_TZ)).astimezone(
pytz.timezone('UTC')).replace(tzinfo=None)
return nowval
adam