Commit 548f2df1 authored by Kirill Smelkov's avatar Kirill Smelkov

*: threading.Lock -> sync.Mutex

Similarly to 78d85cdc (sync: threading.Event -> chan) replace everywhere
threaing.Lock usage with sync.Mutex . This brings 2 goods:

- sync.Mutex becomes more well tested;
- we untie ourselves from threading python module (threading.Lock was
  the last user).
parent 34b7a1f4
......@@ -28,8 +28,8 @@ See the following links about Go contexts:
from __future__ import print_function, absolute_import
from golang import go, chan, select, default, nilchan
from golang import _sync # avoid cycle: context -> sync -> context
from golang import time
import threading
# Context is the interface that every context must implement.
#
......@@ -154,7 +154,7 @@ class _BaseCtx(object):
# does not change after setup.
ctx._parentv = parentv
ctx._mu = threading.Lock()
ctx._mu = _sync.PyMutex()
ctx._children = set() # children of this context - we propagate cancel there (all _BaseCtx)
ctx._err = None
......
......@@ -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 sync
from pytest import raises
from os.path import dirname
import os, sys, threading, inspect, importlib
import os, sys, inspect, importlib
from subprocess import Popen, PIPE
from six.moves import range as xrange
import gc, weakref
......@@ -106,7 +107,7 @@ def test_chan():
# sync: close vs multiple recv
ch = chan()
done = chan()
mu = threading.Lock()
mu = sync.Mutex()
s = set()
def _():
assert ch.recv_() == (None, False)
......
......@@ -26,7 +26,7 @@ See the following link about Go sync package:
from __future__ import print_function, absolute_import
import threading, sys
import sys
from golang import go, chan, defer, func, panic
from golang import context
......@@ -46,7 +46,7 @@ from golang._sync import \
# once.do(doSomething)
class Once(object):
def __init__(once):
once._mu = threading.Lock()
once._mu = Mutex()
once._done = False
def do(once, f):
......@@ -59,7 +59,7 @@ class Once(object):
# WaitGroup allows to wait for collection of tasks to finish.
class WaitGroup(object):
def __init__(wg):
wg._mu = threading.Lock()
wg._mu = Mutex()
wg._count = 0
wg._done = chan() # closed & recreated every time ._count drops to 0
......@@ -113,7 +113,7 @@ class WorkGroup(object):
def __init__(g, ctx):
g._ctx, g._cancel = context.with_cancel(ctx)
g._wg = WaitGroup()
g._mu = threading.Lock()
g._mu = Mutex()
g._err = None
def go(g, f, *argv, **kw):
......
......@@ -22,7 +22,6 @@ from __future__ import print_function, absolute_import
from golang import go, chan
from golang import sync, context, time
import threading
from pytest import raises
from golang.golang_test import import_pyx_tests, panics
from golang.time_test import dt
......@@ -145,7 +144,7 @@ def test_waitgroup():
def test_workgroup():
ctx, cancel = context.with_cancel(context.background())
mu = threading.Lock()
mu = sync.Mutex()
# t1=ok, t2=ok
wg = sync.WorkGroup(ctx)
......
......@@ -27,7 +27,7 @@ See the following link about Go time package:
from __future__ import print_function, absolute_import
from golang import go, chan, select, default, nilchan, panic
import threading
from golang import _sync # avoid cycle: context -> time -> sync -> context
from golang._time import \
pysecond as second, \
......@@ -77,7 +77,7 @@ class Ticker(object):
panic("ticker: dt <= 0")
self.c = chan(1) # 1-buffer -- same as in Go
self._dt = dt
self._mu = threading.Lock()
self._mu = _sync.PyMutex()
self._stop = False
go(self._tick)
......@@ -119,7 +119,7 @@ class Timer(object):
def __init__(self, dt, f=None):
self._f = f
self.c = chan(1) if f is None else nilchan
self._mu = threading.Lock()
self._mu = _sync.PyMutex()
self._dt = None # None - stopped, float - armed
self._ver = 0 # current timer was armed by n'th reset
self.reset(dt)
......
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