Commit 9662785b authored by Kirill Smelkov's avatar Kirill Smelkov

context: Switch time.now() to cimport

parent 89381488
...@@ -32,6 +32,7 @@ from golang import go as pygo, chan as pychan, select as pyselect, default as py ...@@ -32,6 +32,7 @@ from golang import go as pygo, chan as pychan, select as pyselect, default as py
from golang import _sync as _pysync # avoid cycle: context -> sync -> context from golang import _sync as _pysync # avoid cycle: context -> sync -> context
from golang import time as pytime from golang import time as pytime
from golang cimport time
from cython cimport final from cython cimport final
...@@ -101,7 +102,7 @@ def with_deadline(parent, deadline): # -> ctx, cancel ...@@ -101,7 +102,7 @@ def with_deadline(parent, deadline): # -> ctx, cancel
return with_cancel(parent) return with_cancel(parent)
# timeout <= 0 -> already canceled # timeout <= 0 -> already canceled
timeout = deadline - pytime.now() timeout = deadline - time.now()
if timeout <= 0: if timeout <= 0:
ctx, cancel = with_cancel(parent) ctx, cancel = with_cancel(parent)
cancel() cancel()
...@@ -114,7 +115,7 @@ def with_deadline(parent, deadline): # -> ctx, cancel ...@@ -114,7 +115,7 @@ def with_deadline(parent, deadline): # -> ctx, cancel
# #
# it is shorthand for with_deadline(parent, now+timeout). # it is shorthand for with_deadline(parent, now+timeout).
def with_timeout(parent, timeout): # -> ctx, cancel def with_timeout(parent, timeout): # -> ctx, cancel
return with_deadline(parent, pytime.now() + timeout) return with_deadline(parent, time.now() + timeout)
# merge merges 2 contexts into 1. # merge merges 2 contexts into 1.
# #
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment