[Python-checkins] gh-89047: Fix msecs computation so you never end up with 1000 msecs. (GH-96340)
vsajip
webhook-mailer at python.org
Sat Aug 27 08:33:33 EDT 2022
https://github.com/python/cpython/commit/6fbd889d6e937ad255f98b5495b78a06d05640d5
commit: 6fbd889d6e937ad255f98b5495b78a06d05640d5
branch: main
author: Vinay Sajip <vinay_sajip at yahoo.co.uk>
committer: vsajip <vinay_sajip at yahoo.co.uk>
date: 2022-08-27T13:33:24+01:00
summary:
gh-89047: Fix msecs computation so you never end up with 1000 msecs. (GH-96340)
files:
M Lib/logging/__init__.py
M Lib/test/test_logging.py
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index afb5234a0772..c3208a21f499 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -340,7 +340,7 @@ def __init__(self, name, level, pathname, lineno,
self.lineno = lineno
self.funcName = func
self.created = ct
- self.msecs = (ct - int(ct)) * 1000
+ self.msecs = int((ct - int(ct)) * 1000) + 0.0 # see gh-89047
self.relativeCreated = (self.created - _startTime) * 1000
if logThreads:
self.thread = threading.get_ident()
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 99ea2f687551..a67ed07f12c8 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -4261,6 +4261,14 @@ class NoMsecFormatter(logging.Formatter):
f.converter = time.gmtime
self.assertEqual(f.formatTime(r), '21/04/1993 08:03:00')
+ def test_issue_89047(self):
+ f = logging.Formatter(fmt='{asctime}.{msecs:03.0f} {message}', style='{', datefmt="%Y-%m-%d %H:%M:%S")
+ for i in range(2500):
+ time.sleep(0.0004)
+ r = logging.makeLogRecord({'msg': 'Message %d' % (i + 1)})
+ s = f.format(r)
+ self.assertNotIn('.1000', s)
+
class TestBufferingFormatter(logging.BufferingFormatter):
def formatHeader(self, records):
More information about the Python-checkins
mailing list