示例#1
0
def enter_loop(name=None,
               rgstr_stamps=None,
               save_itrs=True,
               keep_subdivisions=True):
    t = timer()
    f.t.last_t = t
    if f.t.stopped:
        raise StoppedError("Timer already stopped when entering loop.")
    if f.t.paused:
        raise PausedError("Timer paused when entering loop.")
    times_priv.assign_subdivisions(UNASGN, keep_subdivisions)
    if name is None:  # Entering anonynous loop.
        if f.t.in_loop:
            raise LoopError("Entering anonymous inner timed loop (not supported).")
        f.t.in_loop = True
        f.t.self_cut += timer() - t
    else:  # Entering a named loop.
        if not f.t.in_loop or name not in f.lp.stamps:  # double check this if-logic
            timer_pub._init_loop_stamp(name, do_lp=False)
            if save_itrs:
                f.s.itrs[name] = []
        if f.t.in_loop and name not in f.lp.stamps:
            f.lp.stamps.append(name)
        f.t.self_cut += timer() - t
        _subdivide_named_loop(name, rgstr_stamps, save_itrs=save_itrs)
    f.create_next_loop(name, rgstr_stamps, save_itrs)
示例#2
0
 def next(self):
     if self._exited:
         raise LoopError(
             "Attempted loop iteration on already exited loop (need a new loop object)."
         )
     if self._first:
         loop.enter_loop(self._name, self._rgstr_stamps, self._save_itrs,
                         self._keep_prev_subdivisions)
         self._first = False
         self._started = True
         self._timer = get_current_timer()
     else:
         if get_current_timer() is not self._timer:
             raise LoopError(
                 "Loop timer mismatch, likely improper subdivision during loop (cannot span iterations)."
             )
         loop.loop_end(self._loop_end_stamp, self._end_stamp_unique,
                       self._keep_end_subdivisions, self._quick_print)
     loop.loop_start()
示例#3
0
 def __iter__(self):
     if self._exited:
         raise LoopError(
             "For-loop object already exited (need a new loop object).")
     loop.enter_loop(self._name, self._rgstr_stamps, self._save_itrs,
                     self._keep_prev_subdivisions)
     self._timer = get_current_timer()
     for i in self._iterable:
         loop.loop_start()
         self._started = True
         yield i
         if self._exited:
             raise LoopError(
                 "Loop mechanism exited improperly (must break).")
         if get_current_timer() is not self._timer:
             raise LoopError(
                 "Loop timer mismatch, likely improper subdivision during loop (cannot span iterations)."
             )
         loop.loop_end(self._loop_end_stamp, self._end_stamp_unique,
                       self._keep_end_subdivisions)
         self._started = False
     loop.exit_loop()
     self._exited = True
示例#4
0
def end_subdivision():
    """
    End a user-induced timing subdivision, returning the previous level in
    the timing hierarchy as the target of timing commands such as stamp().
    Includes a call to stop(); a previous call to stop() is OK.

    Returns:
        None

    Raises:
        GTimerError: If current subdivision was not induced by user.
        LoopError: If current timer is in a timed loop.
    """
    if not f.t.is_user_subdvsn:
        raise GTimerError(
            'Attempted to end a subdivision not started by user.')
    if f.t.in_loop:
        raise LoopError('Cannot close a timer while it is in timed loop.')
    _close_subdivision()
示例#5
0
def reset():
    """
    Reset the timer at the current level in the hierarchy (i.e. might or
    might not be the root).

    Notes:
        Erases timing data but preserves relationship to the hierarchy.  If the
        current timer level was not previously stopped, any timing data from this
        timer (including subdivisions) will be discarded and not added to the next
        higher level in the data structure.  If the current timer was previously
        stopped, then its data has already been pushed into the next higher level.

    Returns:
        float: The current time.

    Raises:
        LoopError: If in a timed loop.
    """
    if f.t.in_loop:
        raise LoopError("Cannot reset a timer while it is in timed loop.")
    f.t.reset()
    f.refresh_shortcuts()
    return f.t.start_t
示例#6
0
def _end_subdivision_named_loop():
    if f.t.is_user_subdvsn:
        raise LoopError("gtimer attempted to end user-generated subdivision at end of named loop.")
    if not f.t.stopped:
        timer_pub.stop()
    f.remove_last_timer()
示例#7
0
 def __enter__(self):
     if self._exited:
         raise LoopError(
             "Loop used as context manager previously exited (make a new one)."
         )
     return self