diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0c6cd4a0..0a903cf9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,10 @@ Changes ======= +3.5.1 +~~~~~ +* FIX: #19 line profiler now works on async functions again + 3.5.0 ~~~~~ * FIX: #109 kernprof fails to write to stdout if stdout was replaced diff --git a/kernprof.py b/kernprof.py index 033357f4..10adc7cd 100755 --- a/kernprof.py +++ b/kernprof.py @@ -9,7 +9,7 @@ # NOTE: This version needs to be manually maintained with the line_profiler # __version__ for now. -__version__ = '3.5.0' +__version__ = '3.5.1' # Guard the import of cProfile such that 3.x people # without lsprof can still use this script. diff --git a/line_profiler/line_profiler.py b/line_profiler/line_profiler.py index 7d9312a9..6d7cc3d4 100755 --- a/line_profiler/line_profiler.py +++ b/line_profiler/line_profiler.py @@ -16,7 +16,7 @@ f'Has it been compiled? Underlying error is ex={ex!r}' ) -__version__ = '3.5.0' +__version__ = '3.5.1' def load_ipython_extension(ip): @@ -27,7 +27,7 @@ def load_ipython_extension(ip): def is_coroutine(f): - return False + return inspect.iscoroutinefunction(f) CO_GENERATOR = 0x0020 @@ -57,6 +57,22 @@ def __call__(self, func): wrapper = self.wrap_function(func) return wrapper + def wrap_coroutine(self, func): + """ + Wrap a Python 3.5 coroutine to profile it. + """ + + @functools.wraps(func) + async def wrapper(*args, **kwds): + self.enable_by_count() + try: + result = await func(*args, **kwds) + finally: + self.disable_by_count() + return result + + return wrapper + def wrap_generator(self, func): """ Wrap a generator to profile it. """