logging module for python reports incorrect timezone under cygwin

2024/10/13 20:16:38

I am running python script that uses logging module under cygwin on Windows 7. The date command reports correct time:

$ date
Tue, Aug 14, 2012  2:47:49 PM

However, the python script is five hours off:

2012-08-14 19:39:06,438: Done!

I don't do anything fancy when I configure logging for the script:

logging.basicConfig(format='%(asctime)-15s: %(message)s', level=logging.DEBUG)

Can someone tell me what is going on and how I can fix it?

Answer

You need to unset the environment "TZ" in your python script prior to any importing the date/time modules. It is set by cygwin but not understood by Windows:

if os.getenv("TZ"):os.unsetenv("TZ")
https://en.xdnf.cn/q/69494.html

Related Q&A

Set ordering of Apps and models in Django admin dashboard

By default, the Django admin dashboard looks like this for me:I want to change the ordering of models in Profile section, so by using codes from here and here I was able to change the ordering of model…

python database / sql programming - where to start

What is the best way to use an embedded database, say sqlite in Python:Should be small footprint. Im only needing few thousands records per table. And just a handful of tables per database. If its one …

How to install Python 3.5 on Raspbian Jessie

I need to install Python 3.5+ on Rasbian (Debian for the Raspberry Pi). Currently only version 3.4 is supported. For the sources I want to compile I have to install:sudo apt-get install -y python3 pyth…

Django - last insert id

I cant get the last insert id like I usually do and Im not sure why.In my view:comment = Comments( ...) comment.save() comment.id #returns NoneIn my Model:class Comments(models.Model):id = models.Integ…

How to check if default value for python function argument is set using inspect?

Im trying to identify the parameters of a function for which default values are not set. Im using inspect.signature(func).parameters.value() function which gives a list of function parameters. Since Im…

OpenCV-Python cv2.CV_CAP_PROP_POS_FRAMES error

Currently, I am using opencv 3.1.0, and I encountered the following error when executing the following code:post_frame = cap.get(cv2.CV_CAP_PROP_POS_FRAMES)I got the following error Message:File "…

How to get the total number of tests passed, failed and skipped from pytest

How can I get to the statistics information of a test session in pytest?Ive tried to define pytest_sessionfinish in the conftest.py file, but I only see testsfailed and testscollected attributes on th…

Tensorflow ArgumentError Running CIFAR-10 example

I am trying to run the CIFAR-10 example of Tensorflow. However when executing python cifar10.py I am getting the error attached below. I have installed Version 0.6.0 of the Tensorflow package using pip…

How to plot multiple density plots on the same figure in python

I know this is going to end up being a really messy plot, but I am curious to know what the most efficient way to do this is. I have some data that looks like this in a csv file:ROI Band Min…

Running Tkinter on Mac

I am an absolute newbie. Im trying to make Python GUI for my school project so I decided to use Tkinter. When I try to import Tkinter it throws this message: >>> import tkinter Traceback (most…