-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1755 from UlrichB22/before_wiki
app.py: skip before_wiki and teardown_wiki for static content
- Loading branch information
Showing
2 changed files
with
39 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Copyright: 2001-2003 Juergen Hermann <[email protected]> | ||
# Copyright: 2003-2006 MoinMoin:ThomasWaldmann | ||
# Copyright: 2024 MoinMoin:UlrichB | ||
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details. | ||
|
||
""" | ||
|
@@ -22,11 +23,12 @@ class Clock: | |
Helper class for measuring the time needed to run code. | ||
Usage: | ||
flaskg.clock.start('mytimer') | ||
flaskg.clock.start("mytimer") | ||
# do something | ||
flaskg.clock.stop('mytimer') | ||
flaskg.clock.stop("mytimer", comment="add this to the log message") | ||
# the optional comment field is added to the log message | ||
# or if you want to use its value later | ||
timerval = flaskg.clock.stop('mytimer') | ||
timerval = flaskg.clock.stop("mytimer") | ||
Starting a timer multiple times is supported but the | ||
one started last has to be stopped first. | ||
|
@@ -40,10 +42,10 @@ def start(self, timer): | |
self.timers[timer] = [] | ||
self.timers[timer].append(time.time()) | ||
|
||
def stop(self, timer): | ||
def stop(self, timer, comment=""): | ||
if timer in self.timers: | ||
value = time.time() - self.timers[timer].pop() | ||
logging.debug(f"timer {timer}({len(self.timers[timer])}): {value * 1000:.2f}ms") | ||
logging.debug(f"timer {timer}({len(self.timers[timer])}): {value * 1000:.2f}ms {comment}") | ||
if not self.timers[timer]: | ||
del self.timers[timer] | ||
return value | ||
|