You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Windows: datetime.datetime.now() raises an OverflowError for date after year 2038 #69342
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2015-09-18.12:00:51.578>created_at=<Date2015-09-17.19:25:39.982>labels= ['interpreter-core', '3.8', 'type-bug', '3.7', 'OS-windows']
title='Windows: datetime.datetime.now() raises an OverflowError for date after year 2038'updated_at=<Date2018-11-22.07:53:26.796>user='https://github.com/vmurashev'
Current time on my machine with Windows7x64 is set to year 2045 for test purposes.
Since Python3.5(amd64) I have an OverflowError when I am trying to call datetime.datetime.now()
It looks like a regress since there was no such error on Python3.4.3
Could anyone please give me a note, whether it would be reasonable for me to wait for a patch in Python3.5.x, or such behavior is common since 3.5 and should not use it in my 'strange' case at all ?
A bit of details:
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.now()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: timestamp too large to convert to C _PyTime_t
>>>
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2045, 4, 2, 2, 42, 8, 359375)
>>>
It looks like between 3.4.3 and 3.5, datetime_best_possible changed from using _PyTime_gettimeofday with a _PyTime_timeval to using _PyTime_AsTimeval with struct timeval. The difference is that _PyTime_timeval appears to have been defined with a proper time_t for secs, where struct timeval is defined (on Windows) with a long which is still 32 bits on Windows, so we reintroduced the Y2K38 problem.
Yeah, the changeset e93eeadef0c3 was the last change to drop the last function of the old PyTime.
Well... in fact, I also had to keep _PyTime_ObjectToTime_t() and _PyTime_ObjectToTimeval() for the exact same reason: support timestamp after the year 2038 on Windows.
Right, the tv_sec field of a timeval structure on Windows has the C type long, whereas it has the type time_t on all other platforms...
I fixed the bug in Python 3.5 and 3.6. Thanks for your bug report. I didn't expect to test year 2038 bug on the latest release, thanks time traveler :-)
changed the title [-]datetime.datetime.now() raises[/-][+]Windows: datetime.datetime.now() raises an OverflowError for date after year 2038[/+]on Sep 18, 2015
I get this error when starting the interpreter in Windows subsystem for Linux (WSL).
I am using Python 2.7.15rc1
$ python --version
Python 2.7.15rc1
$ python
Fatal Python error: _Py_InitializeMainInterpreter: can't initialize time OverflowError: timestamp too large to convert to C _PyTime_t Current thread 0x00007fe547231080 (most recent call first): Aborted (core dumped)
$ python3 --version
Python 3.7.0b3
$ python3
Fatal Python error: _Py_InitializeMainInterpreter: can't initialize timeOverflowError: timestamp too large to convert to C _PyTime_t
Current thread 0x00007f0232c21080 (most recent call first):
Aborted (core dumped)
I get this error when starting the interpreter in Windows subsystem for Linux (WSL).
This bug is currently closed, please open a new bug.
About your issue. I'm not sure if Windows subsystem for Linux is officially supported. How did you install Python 2.7 and 3.7? Are you testing 32-bit or 64-bit Python? (Again, please answer in your new issue.)
I tried 64-bit builds of Python 2.7 and 3.7rc1 (binaries from python.org) on Windows 10 on year 2045: start with no error, time.time() and datetime.datetime.now() don't fail.
I tried Python 2.7.12 and 3.5.2 on Ubuntu 16.04 in WSL on my Windows 10: same, start with no error, time.time() and datetime.datetime.now() don't fail. It's 64-bit Ubuntu with 64-bit binaries for Python 2 and Python 3 (check sys.maxsize).
I even compiled Python 2.7.15 and 3.7rc1 on Ubuntu 16.04 in WSL on my Windows 10: same again, start with no error, time.time() and datetime.datetime.now() don't fail. Python 2 and 3 have been compiled in 64-bit mode, since it's a 64-bit Ubuntu.
Everything is fine. I failed to reproduce your bug.
PetterS commented on Jun 26, 2018
PetterSmannequin
Mannequin
More actions
I also compiled Python myself on WSL.
The bug seemed to appear after computer had been running for a while. Before that, the interpreters were working normally. And after rebooting the problem disappeared.
I created bpo-33965: [Windows WSL] Fatal Python error: _Py_InitializeMainInterpreter: can't initialize time, after year 2038.
srinivasreddy commented on Nov 22, 2018
srinivasreddymannequin
Mannequin
More actions
This bug is happening for 3.6 too. Please see below,
18:14 $ python --version
Python 3.6.3
(upwork) ✔ ~/workspace/personal/assignment [master|✔]
18:16 $ pip install --upgrade pip
Exception:
Traceback (most recent call last):
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
status =self.run(options, args)
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/commands/install.py", line 324, in run
requirement_set.prepare_files(finder)
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/req/req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/req/req_set.py", line 487, in _prepare_file
req_to_install, finder)
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/req/req_set.py", line 428, in _check_skip_installed
req_to_install, upgrade_allowed)
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/index.py", line 465, in find_requirement
all_candidates =self.find_all_candidates(req.name)
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/index.py", line 423, in find_all_candidatesfor page inself._get_pages(url_locations, project_name):
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/index.py", line 568, in _get_pages
page =self._get_page(location)
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/index.py", line 683, in _get_pagereturn HTMLPage.get_page(link, session=self.session)
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/index.py", line 792, in get_page"Cache-Control": "max-age=600",
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 488, in getreturnself.request('GET', url, **kwargs)
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/download.py", line 386, in requestreturnsuper(PipSession, self).request(method, url, *args, **kwargs)
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 475, in request
resp =self.send(prep, **send_kwargs)
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 596, in send
r = adapter.send(request, **kwargs)
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/_vendor/requests/adapters.py", line 423, in send
timeout=timeout
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 595, in urlopen
chunked=chunked)
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 363, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1239, in requestself._send_request(method, url, body, headers, encode_chunked)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1285, in _send_requestself.endheaders(body, encode_chunked=encode_chunked)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1234, in endheadersself._send_output(message_body, encode_chunked=encode_chunked)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1026, in _send_outputself.send(msg)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 964, in sendself.connect()
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/connection.py", line 167, in connect
conn =self._new_conn()
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/connection.py", line 142, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/util/connection.py", line 85, in create_connection
sock.settimeout(timeout)
OverflowError: timestamp too large to convert to C _PyTime_t
You are using pip version 9.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
"""
This bug is happening for 3.6 too. Please see below,
(...)
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/util/connection.py", line 85, in create_connection
sock.settimeout(timeout)
OverflowError: timestamp too large to convert to C _PyTime_t
"""
This error is different: the error occurs on socket.socket.settimeout() and comes from urllib3, not from the Python standard library. You should report this traceback to urllib3.
srinivasreddy commented on Nov 22, 2018
srinivasreddymannequin
Mannequin
More actions
Yikes, Sorry for the spam. I should have double checked.
Activity
vmurashev commentedon Sep 17, 2015
Current time on my machine with Windows7x64 is set to year 2045 for test purposes.
Since Python3.5(amd64) I have an OverflowError when I am trying to call datetime.datetime.now()
It looks like a regress since there was no such error on Python3.4.3
Could anyone please give me a note, whether it would be reasonable for me to wait for a patch in Python3.5.x, or such behavior is common since 3.5 and should not use it in my 'strange' case at all ?
A bit of details:
MojoVampire commentedon Sep 17, 2015
It looks like between 3.4.3 and 3.5, datetime_best_possible changed from using _PyTime_gettimeofday with a _PyTime_timeval to using _PyTime_AsTimeval with struct timeval. The difference is that _PyTime_timeval appears to have been defined with a proper time_t for secs, where struct timeval is defined (on Windows) with a long which is still 32 bits on Windows, so we reintroduced the Y2K38 problem.
The bug was introduced while trying to support bpo-22117: "Rewrite pytime.h to work on nanoseconds" in reve93eeadef0c3: https://hg.python.org/cpython/rev/e93eeadef0c3
python-dev commentedon Sep 18, 2015
New changeset 203134592edf by Victor Stinner in branch 'default':
Issue bpo-25155: Add _PyTime_AsTimevalTime_t() function
https://hg.python.org/cpython/rev/203134592edf
python-dev commentedon Sep 18, 2015
New changeset 4ca99a0a18e4 by Victor Stinner in branch '3.5':
Issue bpo-25155: Add _PyTime_AsTimevalTime_t() function
https://hg.python.org/cpython/rev/4ca99a0a18e4
vstinner commentedon Sep 18, 2015
Oh wow, I didn't expect such much headaches when I worked on unifiying the code to handle timestamps in the C part of CPython...
Yeah, the changeset e93eeadef0c3 was the last change to drop the last function of the old PyTime.
Well... in fact, I also had to keep _PyTime_ObjectToTime_t() and _PyTime_ObjectToTimeval() for the exact same reason: support timestamp after the year 2038 on Windows.
Right, the tv_sec field of a timeval structure on Windows has the C type long, whereas it has the type time_t on all other platforms...
I fixed the bug in Python 3.5 and 3.6. Thanks for your bug report. I didn't expect to test year 2038 bug on the latest release, thanks time traveler :-)
python-dev commentedon Sep 18, 2015
New changeset 5bfcccf229c4 by Victor Stinner in branch '3.5':
Issue bpo-25155: document the bugfix in Misc/NEWS
https://hg.python.org/cpython/rev/5bfcccf229c4
[-]datetime.datetime.now() raises[/-][+]Windows: datetime.datetime.now() raises an OverflowError for date after year 2038[/+]python-dev commentedon Sep 18, 2015
New changeset f1cc1f379b00 by Victor Stinner in branch '3.5':
Issue bpo-25155: Fix _PyTime_Divide() rounding
https://hg.python.org/cpython/rev/f1cc1f379b00
PetterS commentedon Jun 25, 2018
I get this error when starting the interpreter in Windows subsystem for Linux (WSL).
I am using Python 2.7.15rc1
$ python --version Python 2.7.15rc1 $ python Fatal Python error: _Py_InitializeMainInterpreter: can't initialize time OverflowError: timestamp too large to convert to C _PyTime_t Current thread 0x00007fe547231080 (most recent call first): Aborted (core dumped)PetterS commentedon Jun 25, 2018
For Python 3:
Current thread 0x00007f0232c21080 (most recent call first):
Aborted (core dumped)
vstinner commentedon Jun 25, 2018
This bug is currently closed, please open a new bug.
About your issue. I'm not sure if Windows subsystem for Linux is officially supported. How did you install Python 2.7 and 3.7? Are you testing 32-bit or 64-bit Python? (Again, please answer in your new issue.)
vstinner commentedon Jun 25, 2018
I tried 64-bit builds of Python 2.7 and 3.7rc1 (binaries from python.org) on Windows 10 on year 2045: start with no error, time.time() and datetime.datetime.now() don't fail.
I tried Python 2.7.12 and 3.5.2 on Ubuntu 16.04 in WSL on my Windows 10: same, start with no error, time.time() and datetime.datetime.now() don't fail. It's 64-bit Ubuntu with 64-bit binaries for Python 2 and Python 3 (check sys.maxsize).
I even compiled Python 2.7.15 and 3.7rc1 on Ubuntu 16.04 in WSL on my Windows 10: same again, start with no error, time.time() and datetime.datetime.now() don't fail. Python 2 and 3 have been compiled in 64-bit mode, since it's a 64-bit Ubuntu.
Everything is fine. I failed to reproduce your bug.
PetterS commentedon Jun 26, 2018
I also compiled Python myself on WSL.
The bug seemed to appear after computer had been running for a while. Before that, the interpreters were working normally. And after rebooting the problem disappeared.
vstinner commentedon Jun 26, 2018
I created bpo-33965: [Windows WSL] Fatal Python error: _Py_InitializeMainInterpreter: can't initialize time, after year 2038.
srinivasreddy commentedon Nov 22, 2018
This bug is happening for 3.6 too. Please see below,
vstinner commentedon Nov 22, 2018
Hi,
"""
This bug is happening for 3.6 too. Please see below,
(...)
File "/home/dtdev/virtual/upwork/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/util/connection.py", line 85, in create_connection
sock.settimeout(timeout)
OverflowError: timestamp too large to convert to C _PyTime_t
"""
This error is different: the error occurs on socket.socket.settimeout() and comes from urllib3, not from the Python standard library. You should report this traceback to urllib3.
srinivasreddy commentedon Nov 22, 2018
Yikes, Sorry for the spam. I should have double checked.