Skip to content

Commit

Permalink
fix strange namedfile issues
Browse files Browse the repository at this point in the history
  • Loading branch information
impact27 committed Oct 12, 2021
1 parent 92354ca commit fffca64
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions spyder/plugins/profiler/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,21 +359,20 @@ def show_profile_buffer(self, prof_buffer):
"""Show profile file."""
if not prof_buffer:
return
temp = tempfile.NamedTemporaryFile(delete=False)
temp.write(prof_buffer)
filename = temp.name
# Release the file (Important on Window to avoid file locks)
temp.close()
# Open again
self.load_data(filename)
# Delete
os.unlink(filename)
with tempfile.TemporaryDirectory() as dir:
filename = os.path.join(dir, "tem.prof")
with open(filename, "bw") as f:
f.write(prof_buffer)
self.load_data(filename)
# Show
self.show_tree()
self.sig_display_requested.emit(self)

def load_data(self, profdatafile):
"""Load profiler data saved by profile/cProfile module"""
if not os.path.isfile(profdatafile):
self.profdata = None
return
import pstats
# Fixes spyder-ide/spyder#6220.
try:
Expand Down

0 comments on commit fffca64

Please sign in to comment.