Skip to content

Commit ad0bb96

Browse files
committed
[GR-16622] fix thread builtin
PullRequest: graalpython/557
2 parents aabeb95 + ddd1d48 commit ad0bb96

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_thread.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -301,7 +301,8 @@ def setUp(self):
301301

302302
def tearDown(self):
303303
support.threading_cleanup(*self._threads)
304-
support.reap_children()
304+
# TODO: revert patch when os.waitpid(-1, ...) is implemented
305+
# support.reap_children()
305306

306307
def assertLess(self, a, b, msg=None):
307308
if not a < b:

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/AbstractPythonLock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public abstract class AbstractPythonLock extends PythonBuiltinObject {
4747

4848
public static final double TIMEOUT_MAX = 2 ^ 31;
4949
public static final boolean DEFAULT_BLOCKING = true;
50-
public static final double DEFAULT_TIMEOUT = -1.0;
50+
public static final double UNSET_TIMEOUT = -1.0;
5151

5252
AbstractPythonLock(LazyPythonClass cls) {
5353
super(cls);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/thread/LockBuiltins.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
package com.oracle.graal.python.builtins.objects.thread;
4242

4343
import static com.oracle.graal.python.builtins.objects.thread.AbstractPythonLock.DEFAULT_BLOCKING;
44-
import static com.oracle.graal.python.builtins.objects.thread.AbstractPythonLock.DEFAULT_TIMEOUT;
44+
import static com.oracle.graal.python.builtins.objects.thread.AbstractPythonLock.UNSET_TIMEOUT;
4545
import static com.oracle.graal.python.builtins.objects.thread.AbstractPythonLock.TIMEOUT_MAX;
4646
import static com.oracle.graal.python.nodes.SpecialMethodNames.__ENTER__;
4747
import static com.oracle.graal.python.nodes.SpecialMethodNames.__EXIT__;
@@ -109,26 +109,28 @@ private CastToBooleanNode getCastToBooleanNode() {
109109
boolean doAcquire(VirtualFrame frame, AbstractPythonLock self, Object blocking, Object timeout) {
110110
// args setup
111111
boolean isBlocking = (blocking instanceof PNone) ? DEFAULT_BLOCKING : getCastToBooleanNode().executeBoolean(frame, blocking);
112-
double timeoutSeconds = DEFAULT_TIMEOUT;
112+
double timeoutSeconds = UNSET_TIMEOUT;
113113
if (!(timeout instanceof PNone)) {
114-
if (!isBlocking) {
115-
throw raise(ValueError, "can't specify a timeout for a non-blocking call");
116-
}
117-
118114
timeoutSeconds = getCastToDoubleNode().execute(frame, timeout);
119115

120-
if (timeoutSeconds < 0) {
121-
throw raise(ValueError, "timeout value must be positive");
122-
} else if (timeoutSeconds > TIMEOUT_MAX) {
123-
throw raise(OverflowError, "timeout value is too large");
116+
if (timeoutSeconds != UNSET_TIMEOUT) {
117+
if (!isBlocking) {
118+
throw raise(ValueError, "can't specify a timeout for a non-blocking call");
119+
}
120+
121+
if (timeoutSeconds < 0) {
122+
throw raise(ValueError, "timeout value must be positive");
123+
} else if (timeoutSeconds > TIMEOUT_MAX) {
124+
throw raise(OverflowError, "timeout value is too large");
125+
}
124126
}
125127
}
126128

127129
// acquire lock
128130
if (isBlockingProfile.profile(!isBlocking)) {
129131
return self.acquireNonBlocking();
130132
} else {
131-
if (defaultTimeoutProfile.profile(timeoutSeconds == DEFAULT_TIMEOUT)) {
133+
if (defaultTimeoutProfile.profile(timeoutSeconds == UNSET_TIMEOUT)) {
132134
return self.acquireBlocking();
133135
} else {
134136
return self.acquireTimeout(timeoutSeconds);

0 commit comments

Comments
 (0)