Author: Ronan Lamy <[email protected]>
Branch: py3k
Changeset: r85895:4984ab3961af
Date: 2016-07-28 16:49 +0100
http://bitbucket.org/pypy/pypy/changeset/4984ab3961af/
Log: Fix _thread module
diff --git a/pypy/module/thread/__init__.py b/pypy/module/thread/__init__.py
--- a/pypy/module/thread/__init__.py
+++ b/pypy/module/thread/__init__.py
@@ -4,7 +4,7 @@
class Module(MixedModule):
applevel_name = '_thread'
-
+
appleveldefs = {
}
@@ -22,7 +22,7 @@
'LockType': 'os_lock.Lock',
'RLock': 'os_lock.W_RLock',
'_local': 'os_local.Local',
- 'TIMEOUT_MAX': 'space.wrap(float(os_lock.TIMEOUT_MAX) /
1000000.0)',
+ 'TIMEOUT_MAX': 'space.wrap(float(os_lock.TIMEOUT_MAX //
1000000))',
'error': 'space.fromcache(error.Cache).w_error',
}
diff --git a/pypy/module/thread/os_lock.py b/pypy/module/thread/os_lock.py
--- a/pypy/module/thread/os_lock.py
+++ b/pypy/module/thread/os_lock.py
@@ -9,12 +9,14 @@
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import TypeDef, make_weakref_descr
from pypy.interpreter.error import oefmt
-from rpython.rlib.rarithmetic import (
- r_longlong, ovfcheck, ovfcheck_float_to_longlong)
+from rpython.rlib.rarithmetic import r_longlong, ovfcheck,
ovfcheck_float_to_longlong
# Force the declaration of the type 'thread.LockType' for RPython
#import pypy.module.thread.rpython.exttable
+LONGLONG_MAX = r_longlong(2 ** (r_longlong.BITS - 1) - 1)
+TIMEOUT_MAX = LONGLONG_MAX
+
RPY_LOCK_FAILURE, RPY_LOCK_ACQUIRED, RPY_LOCK_INTR = range(3)
def parse_acquire_args(space, blocking, timeout):
@@ -29,8 +31,7 @@
elif timeout == -1.0:
microseconds = -1
else:
- # 0.0 => 0.0, but otherwise tends to round up
- timeout = timeout * 1e6 + 0.999
+ timeout *= 1e6
try:
microseconds = ovfcheck_float_to_longlong(timeout)
except OverflowError:
@@ -47,8 +48,7 @@
# Run signal handlers if we were interrupted
space.getexecutioncontext().checksignals()
if microseconds >= 0:
- microseconds = r_longlong((endtime - (time.time() * 1e6))
- + 0.999)
+ microseconds = r_longlong(endtime - (time.time() * 1e6))
# Check for negative values, since those mean block
# forever
if microseconds <= 0:
@@ -116,7 +116,7 @@
Lock.typedef = TypeDef(
"_thread.lock",
- __doc__ = """\
+ __doc__="""\
A lock object is a synchronization primitive. To create a lock,
call the thread.allocate_lock() function. Methods are:
@@ -127,16 +127,16 @@
A lock is not owned by the thread that locked it; another thread may
unlock it. A thread attempting to lock a lock that it has already locked
will block until another thread unlocks it. Deadlocks may ensue.""",
- acquire = interp2app(Lock.descr_lock_acquire),
- release = interp2app(Lock.descr_lock_release),
- locked = interp2app(Lock.descr_lock_locked),
- __enter__ = interp2app(Lock.descr__enter__),
- __exit__ = interp2app(Lock.descr__exit__),
+ acquire=interp2app(Lock.descr_lock_acquire),
+ release=interp2app(Lock.descr_lock_release),
+ locked=interp2app(Lock.descr_lock_locked),
+ __enter__=interp2app(Lock.descr__enter__),
+ __exit__=interp2app(Lock.descr__exit__),
# Obsolete synonyms
- acquire_lock = interp2app(Lock.descr_lock_acquire),
- release_lock = interp2app(Lock.descr_lock_release),
- locked_lock = interp2app(Lock.descr_lock_locked),
- )
+ acquire_lock=interp2app(Lock.descr_lock_acquire),
+ release_lock=interp2app(Lock.descr_lock_release),
+ locked_lock=interp2app(Lock.descr_lock_locked),
+)
def allocate_lock(space):
@@ -201,7 +201,6 @@
return space.wrap(r)
-
def release_w(self, space):
"""Release the lock, allowing another thread that is blocked waiting
for
the lock to acquire the lock. The lock must be in the locked state,
diff --git a/pypy/module/thread/test/test_lock.py
b/pypy/module/thread/test/test_lock.py
--- a/pypy/module/thread/test/test_lock.py
+++ b/pypy/module/thread/test/test_lock.py
@@ -61,18 +61,15 @@
assert lock.acquire(False) is False
assert lock.acquire(True, timeout=.1) is False
- def test_py3k_acquire_timeout_overflow(self):
- import thread
- lock = thread.allocate_lock()
- if not hasattr(lock, '_py3k_acquire'):
- skip("missing lock._py3k_acquire()")
+ def test_timeout_overflow(self):
+ import _thread
+ lock = _thread.allocate_lock()
maxint = 2**63 - 1
- boundary = int(maxint * 1e-6)
for i in [-100000, -10000, -1000, -100, -10, -1, 0,
1, 10, 100, 1000, 10000, 100000]:
timeout = (maxint + i) * 1e-6
try:
- lock._py3k_acquire(True, timeout=timeout)
+ lock.acquire(True, timeout=timeout)
except OverflowError:
got_ovf = True
else:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit