From de2f96dac725ffb32f6cce36e2ee394e313eb315 Mon Sep 17 00:00:00 2001 From: Douglas Blank Date: Sat, 10 Jul 2021 11:00:49 -0700 Subject: [PATCH 1/4] Make timing work with jupyterlite JupyterLite has a resource, but not getrusage(). This make the code a little more general. --- IPython/utils/timing.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/IPython/utils/timing.py b/IPython/utils/timing.py index 9a31affadf0..600a08092c9 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 not None and hasattr(resource, "getrusage"): def clocku(): """clocku() -> floating point number From 75bdd216cb3581ba5f1bf8eb81411f7a54dbb9e6 Mon Sep 17 00:00:00 2001 From: Douglas Blank Date: Sat, 10 Jul 2021 11:07:14 -0700 Subject: [PATCH 2/4] Fix typo --- IPython/utils/timing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IPython/utils/timing.py b/IPython/utils/timing.py index 600a08092c9..c4acd6f0412 100644 --- a/IPython/utils/timing.py +++ b/IPython/utils/timing.py @@ -27,7 +27,7 @@ resource = None # Some implementations (like jyputerlite) don't have getrusage -if resource not None and hasattr(resource, "getrusage"): +if resource is not None and hasattr(resource, "getrusage"): def clocku(): """clocku() -> floating point number From eb5685b0ac2884dfadac25f5b7cc13ff229e3be9 Mon Sep 17 00:00:00 2001 From: Douglas Blank Date: Sat, 10 Jul 2021 11:08:34 -0700 Subject: [PATCH 3/4] Fix else --- IPython/utils/timing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IPython/utils/timing.py b/IPython/utils/timing.py index c4acd6f0412..16de71cf471 100644 --- a/IPython/utils/timing.py +++ b/IPython/utils/timing.py @@ -61,7 +61,7 @@ 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 From f2bc8135fe942f0c3a60c050b6f2159396324288 Mon Sep 17 00:00:00 2001 From: Douglas Blank Date: Sat, 10 Jul 2021 11:13:26 -0700 Subject: [PATCH 4/4] Fix formatting --- IPython/utils/timing.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/IPython/utils/timing.py b/IPython/utils/timing.py index 16de71cf471..32741acdd9c 100644 --- a/IPython/utils/timing.py +++ b/IPython/utils/timing.py @@ -61,6 +61,8 @@ def clock2(): Similar to clock(), but return a tuple of user/system times.""" return resource.getrusage(resource.RUSAGE_SELF)[:2] + + else: # There is no distinction of user/system time under windows, so we just use # time.perff_counter() for everything...