From fe039b7b97ee171ca9bd3242be17dedd094edbd9 Mon Sep 17 00:00:00 2001 From: Julien Cristau Date: Wed, 29 Jan 2025 15:32:14 +0100 Subject: [PATCH] run-task: silence python 3.12 deprecation warning ``` /usr/local/bin/run-task:118: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC). now = datetime.datetime.utcnow().isoformat().encode("utf-8") ``` This slightly changes the output, replacing `Z` with `+00:00` for the timezone component. --- src/taskgraph/run-task/run-task | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/taskgraph/run-task/run-task b/src/taskgraph/run-task/run-task index f54affbf4..eadacf084 100755 --- a/src/taskgraph/run-task/run-task +++ b/src/taskgraph/run-task/run-task @@ -115,10 +115,12 @@ NULL_REVISION = "0000000000000000000000000000000000000000" def print_line(prefix, m): - now = datetime.datetime.utcnow().isoformat().encode("utf-8") - # slice microseconds to 3 decimals. - now = now[:-3] if now[-7:-6] == b"." else now - sys.stdout.buffer.write(b"[%s %sZ] %s" % (prefix, now, m)) + now = ( + datetime.datetime.now(tz=datetime.timezone.utc) + .isoformat(timespec="milliseconds") + .encode("utf-8") + ) + sys.stdout.buffer.write(b"[%s %s] %s" % (prefix, now, m)) sys.stdout.buffer.flush()