Skip to content

Commit 89ad7de

Browse files
committed
Accept objects in time.sleep()
1 parent 197a40b commit 89ad7de

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,17 @@ Object sleep(VirtualFrame frame, double seconds,
331331
return PNone.NONE;
332332
}
333333

334+
@Specialization(guards = "lib.canBeJavaDouble(secondsObj)")
335+
Object sleepObj(VirtualFrame frame, Object secondsObj,
336+
@Shared("branchProfile") @Cached BranchProfile profile,
337+
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
338+
double seconds = lib.asJavaDouble(secondsObj);
339+
double deadline = timeSeconds() + seconds;
340+
doSleep(seconds, deadline);
341+
getContext().triggerAsyncActions(frame, profile);
342+
return PNone.NONE;
343+
}
344+
334345
@TruffleBoundary
335346
private static void doSleep(double seconds, double deadline) {
336347
double secs = seconds;

0 commit comments

Comments
 (0)