Skip to content

Commit

Permalink
Merge from 3.x: PR #6238
Browse files Browse the repository at this point in the history
Fixes #6220
  • Loading branch information
ccordoba12 committed Jan 18, 2018
2 parents 74576d1 + 687f3e3 commit 11b3823
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions spyder_profiler/widgets/profilergui.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def start(self, wdir=None, args=None, pythonpath=None):
lambda: self.read_output(error=True))
self.process.finished.connect(lambda ec, es=QProcess.ExitStatus:
self.finished(ec, es))
self.stop_button.clicked.connect(self.process.kill)
self.stop_button.clicked.connect(self.kill)

if pythonpath is not None:
env = [to_text_string(_pth)
Expand All @@ -278,6 +278,7 @@ def start(self, wdir=None, args=None, pythonpath=None):

self.output = ''
self.error_output = ''
self.stopped = False

p_args = ['-m', 'cProfile', '-o', self.DATAPATH]
if os.name == 'nt':
Expand All @@ -300,7 +301,12 @@ def start(self, wdir=None, args=None, pythonpath=None):
if not running:
QMessageBox.critical(self, _("Error"),
_("Process failed to start"))


def kill(self):
"""Stop button pressed."""
self.process.kill()
self.stopped = True

def set_running_state(self, state=True):
self.start_button.setEnabled(not state)
self.stop_button.setEnabled(state)
Expand Down Expand Up @@ -346,6 +352,11 @@ def show_data(self, justanalyzed=False):
if not filename:
return

if self.stopped:
self.datelabel.setText(_('Run stopped by user.'))
self.datatree.initialize_view()
return

self.datelabel.setText(_('Sorting data, please wait...'))
QApplication.processEvents()

Expand Down Expand Up @@ -465,13 +476,16 @@ def initialize_view(self):
def load_data(self, profdatafile):
"""Load profiler data saved by profile/cProfile module"""
import pstats
stats_indi = [pstats.Stats(profdatafile),]
try:
stats_indi = [pstats.Stats(profdatafile), ]
except (OSError, IOError):
return
self.profdata = stats_indi[0]

if self.compare_file is not None:
try:
stats_indi.append(pstats.Stats(self.compare_file))
except IOError as e:
except (OSError, IOError) as e:
QMessageBox.critical(
self, _("Error"),
_("Error when trying to load profiler results"))
Expand Down

0 comments on commit 11b3823

Please sign in to comment.