Skip to content

Commit 9164239

Browse files
committed
fix datetime.utcnow deprecation warnings
1 parent d960efa commit 9164239

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

examples/function_wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime
1+
import datetime
22

33
from taskbadger import track
44

@@ -7,7 +7,7 @@
77
def my_task(arg1, arg2, kwarg1=None, kwarg2="demo"):
88
print("Hello from my_task")
99
print(f"arg1={arg1}, arg2={arg2}, kwarg1={kwarg1}, kwarg2={kwarg2}")
10-
return ["Hello from my_task", datetime.utcnow()]
10+
return ["Hello from my_task", datetime.datetime.now(datetime.timezone.utc)]
1111

1212

1313
if __name__ == "__main__":

integration_tests/test_basics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from datetime import datetime
1+
import datetime
22

33
import taskbadger as badger
44
from taskbadger import StatusEnum
55

66

77
def test_basics():
8-
data = {"now": datetime.utcnow().isoformat()}
8+
data = {"now": datetime.datetime.now(datetime.timezone.utc).isoformat()}
99
task = badger.create_task("test basics", data=data)
1010
task.success(100)
1111
assert task.status == StatusEnum.SUCCESS

taskbadger/process.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import datetime
12
import subprocess
23
import threading
34
import time
4-
from datetime import datetime
55

66

77
class ProcessRunner:
@@ -13,7 +13,7 @@ def __init__(self, process_args, env, capture_output: bool, update_frequency: in
1313
self.returncode = None
1414

1515
def run(self):
16-
last_update = datetime.utcnow()
16+
last_update = datetime.datetime.now(datetime.timezone.utc)
1717

1818
kwargs = {}
1919
if self.capture_output:
@@ -28,7 +28,7 @@ def run(self):
2828
while process.poll() is None:
2929
time.sleep(0.1)
3030
if _should_update(last_update, self.update_frequency):
31-
last_update = datetime.utcnow()
31+
last_update = datetime.datetime.now(datetime.timezone.utc)
3232
if self.capture_output:
3333
yield {"stdout": stdout.read(), "stderr": stderr.read()}
3434
else:
@@ -75,4 +75,4 @@ def __bool__(self):
7575

7676

7777
def _should_update(last_update: datetime, update_frequency_seconds):
78-
return (datetime.utcnow() - last_update).total_seconds() >= update_frequency_seconds
78+
return (datetime.datetime.now(datetime.timezone.utc) - last_update).total_seconds() >= update_frequency_seconds

0 commit comments

Comments
 (0)