From 78bbe198731da678dc453c80c5f7515faf548198 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Sat, 31 Jul 2021 15:49:16 +0200 Subject: [PATCH] Backport PR #13050: Make Ipython.utils.timing work with jupyterlite --- IPython/utils/timing.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/IPython/utils/timing.py b/IPython/utils/timing.py index 9a31affadf0..32741acdd9c 100644 --- a/IPython/utils/timing.py +++ b/IPython/utils/timing.py @@ -23,6 +23,11 @@ # If possible (Unix), use the resource module instead of time.clock() try: import resource +except ImportError: + resource = None + +# Some implementations (like jyputerlite) don't have getrusage +if resource is not None and hasattr(resource, "getrusage"): def clocku(): """clocku() -> floating point number @@ -56,7 +61,9 @@ def clock2(): Similar to clock(), but return a tuple of user/system times.""" return resource.getrusage(resource.RUSAGE_SELF)[:2] -except ImportError: + + +else: # There is no distinction of user/system time under windows, so we just use # time.perff_counter() for everything... clocku = clocks = clock = time.perf_counter