Commit c3bd2c50 authored by Kirill Smelkov's avatar Kirill Smelkov

*: Use golang.time universally

After 9c260fde (time: New package that mirrors Go's time) we have
golang.time.now and golang.time.sleep and it makes it a more
self-dependent system if timing facility is used through golang.time
instead of outside std time module.

For now this is only a "cleanness" change, but will become important once
we start adding pyx-level nogil API to pygolang - there it will be
important to use golang.time.* for correctness.
parent 78d85cdc
......@@ -21,9 +21,10 @@
from __future__ import print_function, absolute_import
from golang import go, chan, select, default, nilchan, _PanicError, func, panic, defer, recover
from golang import time
from pytest import raises
from os.path import dirname
import os, sys, time, threading, inspect, subprocess
import os, sys, threading, inspect, subprocess
from six.moves import range as xrange
import golang
......@@ -74,14 +75,14 @@ def waitBlocked(chanop):
else:
panic("wait blocked: unexpected chan method: %r" % (chanop,))
t0 = time.time()
t0 = time.now()
while 1:
with ch._mu:
if recv and len(ch._recvq) > 0:
return
if send and len(ch._sendq) > 0:
return
now = time.time()
now = time.now()
if now-t0 > 10: # waited > 10 seconds - likely deadlock
panic("deadlock")
time.sleep(0) # yield to another thread / coroutine
......
......@@ -21,8 +21,8 @@
from __future__ import print_function, absolute_import
from golang import go, chan
from golang import sync, context
import time, threading
from golang import sync, context, time
import threading
from pytest import raises
from golang.golang_test import panics
from six.moves import range as xrange
......
......@@ -21,7 +21,7 @@
from __future__ import print_function, absolute_import
from time import time
from golang import time
from math import ceil, log10
......@@ -44,13 +44,13 @@ class B:
if self._t_start is not None:
return
self._t_start = time()
self._t_start = time.now()
def stop_timer(self):
if self._t_start is None:
return
t = time()
t = time.now()
self._t_total += t - self._t_start
self._t_start = None
......
......@@ -22,7 +22,8 @@
from __future__ import print_function, absolute_import
from golang import go, chan
import os, sys, time
from golang import time
import os, sys
def main():
......
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