Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python 3 support #1

Merged
merged 2 commits into from
Apr 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions import_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ def compute_intime(parent, full_stack, elapsed, ordered_visited, visited, depth=

class ImportProfilerContext(object):
def __init__(self):
self._original_importer = __builtins__["__import__"]
self._original_importer = getattr(__builtins__, "__import__")
self._import_stack = ImportStack()

def enable(self):
__builtins__["__import__"] = self._profiled_import
setattr(__builtins__, "__import__", self._profiled_import)

def disable(self):
__builtins__["__import__"] = self._original_importer
setattr(__builtins__, "__import__", self._original_importer)

def print_info(self, threshold=1.):
""" Print profiler results.
Expand Down Expand Up @@ -116,7 +116,7 @@ def __exit__(self, *a, **kw):
self.disable()

def _profiled_import(self, name, globals=None, locals=None, fromlist=None,
level=-1, *a, **kw):
level=0, *a, **kw):
if globals is None:
context_name = None
else:
Expand Down