Skip to content

Commit

Permalink
Attempt to work around windows issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Erotemic committed Sep 24, 2024
1 parent 1abde89 commit 8c5a4dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions line_profiler/_line_profiler.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ cdef class LineProfiler:
self.code_hash_map = {}
self.dupes_map = {}
self.timer_unit = hpTimerUnit()
# Create a data store for thread-local objects
# https://docs.python.org/3/library/threading.html#thread-local-data
self.threaddata = threading.local()

for func in functions:
Expand Down
14 changes: 11 additions & 3 deletions line_profiler/line_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,17 @@ def show_func(filename, start_lineno, func_name, timings, unit,
else:
for lineno, line in zip(linenos, sublines):
nhits, time, per_hit, percent = display.get(lineno, empty)
txt = template % (lineno, nhits, time, per_hit, percent,
line.rstrip('\n').rstrip('\r'))
stream.write(txt)
line_ = line.rstrip('\n').rstrip('\r')
txt = template % (lineno, nhits, time, per_hit, percent, line_)
try:
stream.write(txt)
except UnicodeEncodeError as ex:
# todo: better handling of windows encoding issue
# for now just work around it
line_ = f'{ex!r} - help wanted for a fix'
txt = template % (lineno, nhits, time, per_hit, percent, line_)
stream.write(txt)

stream.write('\n')
stream.write('\n')

Expand Down

0 comments on commit 8c5a4dd

Please sign in to comment.