def rtime_example(): # Return the time in seconds since the epoch as a floating point number. print rtime.time() # Suspend execution of the calling thread for the given number of seconds. rtime.sleep(3) # On Unix, return the current processor time as a floating point number # expressed in seconds. print rtime.clock()
def _simple_sleep(space, secs, interruptible): if secs == 0.0 or not interruptible: rtime.sleep(secs) else: millisecs = int(secs * 1000) interrupt_event = space.fromcache(State).get_interrupt_event() rwin32.ResetEvent(interrupt_event) rc = rwin32.WaitForSingleObject(interrupt_event, millisecs) if rc == rwin32.WAIT_OBJECT_0: # Yield to make sure real Python signal handler # called. rtime.sleep(0.001) raise wrap_oserror(space, OSError(EINTR, "sleep() interrupted"))
def sleep(space, w_secs): ns = timestamp_w(space, w_secs) if not (ns >= 0): raise oefmt(space.w_ValueError, "sleep length must be non-negative") end_time = _monotonic(space) + float(ns) / SECS_TO_NS while True: if _WIN: # as decreed by Guido, only the main thread can be # interrupted. main_thread = space.fromcache(State).main_thread interruptible = (main_thread == thread.get_ident()) millisecs = ns // MS_TO_NS if millisecs == 0 or not interruptible: rtime.sleep(float(ns) / SECS_TO_NS) break interrupt_event = space.fromcache(State).get_interrupt_event() rwin32.ResetEvent(interrupt_event) rc = rwin32.WaitForSingleObject(interrupt_event, millisecs) if rc != rwin32.WAIT_OBJECT_0: break else: void = lltype.nullptr(rffi.VOIDP.TO) with lltype.scoped_alloc(TIMEVAL) as t: seconds = ns // SECS_TO_NS us = (ns % SECS_TO_NS) // US_TO_NS rffi.setintfield(t, 'c_tv_sec', int(seconds)) rffi.setintfield(t, 'c_tv_usec', int(us)) res = rffi.cast(rffi.LONG, c_select(0, void, void, void, t)) if res == 0: break # normal path if rposix.get_saved_errno() != EINTR: raise exception_from_saved_errno(space, space.w_OSError) space.getexecutioncontext().checksignals() secs = end_time - _monotonic(space) # retry if secs <= 0: break
def sleep(space, secs): _check_sleep_arg(space, secs) rtime.sleep(secs)
def sleep(space, secs): if secs < 0: raise OperationError(space.w_IOError, space.wrap("Invalid argument: negative time in sleep")) rtime.sleep(secs)
def sleep(space, secs): if secs < 0: raise OperationError( space.w_IOError, space.wrap("Invalid argument: negative time in sleep")) rtime.sleep(secs)
def sleep(space, secs): if secs < 0: raise oefmt(space.w_IOError, "Invalid argument: negative time in sleep") rtime.sleep(secs)