@@ -471,7 +471,19 @@ cdef class LineProfiler:
471471
472472 @property
473473 def c_last_time (self ):
474- return (< dict > self ._c_last_time)[threading.get_ident()]
474+ """
475+ Raises:
476+ KeyError
477+ If no profiling data is available on the current thread.
478+ """
479+ try :
480+ return (< dict > self ._c_last_time)[threading.get_ident()]
481+ except KeyError as e:
482+ # We haven't actually profiled anything yet
483+ raise (KeyError (' No profiling data on the current thread '
484+ ' (`threading.get_ident()` = '
485+ f' {threading.get_ident()})' )
486+ .with_traceback(e.__traceback__)) from None
475487
476488 @property
477489 def code_map (self ):
@@ -500,13 +512,12 @@ cdef class LineProfiler:
500512 line_profiler 4.0 no longer directly maintains last_time, but this will
501513 construct something similar for backwards compatibility.
502514 """
503- c_last_time = (< dict > self ._c_last_time)[threading.get_ident()]
504- code_hash_map = self .code_hash_map
515+ c_last_time = self .c_last_time
505516 py_last_time = {}
506- for code, code_hashes in code_hash_map.items() :
507- for code_hash in code_hashes:
508- if code_hash in c_last_time:
509- py_last_time[code] = c_last_time[code_hash ]
517+ for code in self .code_hash_map :
518+ block_hash = hash (code.co_code)
519+ if block_hash in c_last_time:
520+ py_last_time[code] = c_last_time[block_hash ]
510521 return py_last_time
511522
512523
0 commit comments