Skip to content

Commit 7e01bbb

Browse files
authored
run-task: silence python 3.12 deprecation warning (#639)
``` /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.
1 parent 01596a6 commit 7e01bbb

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/taskgraph/run-task/run-task

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,12 @@ NULL_REVISION = "0000000000000000000000000000000000000000"
115115

116116

117117
def print_line(prefix, m):
118-
now = datetime.datetime.utcnow().isoformat().encode("utf-8")
119-
# slice microseconds to 3 decimals.
120-
now = now[:-3] if now[-7:-6] == b"." else now
121-
sys.stdout.buffer.write(b"[%s %sZ] %s" % (prefix, now, m))
118+
now = (
119+
datetime.datetime.now(tz=datetime.timezone.utc)
120+
.isoformat(timespec="milliseconds")
121+
.encode("utf-8")
122+
)
123+
sys.stdout.buffer.write(b"[%s %s] %s" % (prefix, now, m))
122124
sys.stdout.buffer.flush()
123125

124126

0 commit comments

Comments
 (0)