Skip to content
Snippets Groups Projects
Commit 7e147e3f authored by Martyn Gigg's avatar Martyn Gigg
Browse files

Restrict single code tab from concurrent execution.

Refs #21251
parent 8bbee9de
No related branches found
No related tags found
No related merge requests found
...@@ -64,8 +64,8 @@ class PythonCodeExecution(QObject): ...@@ -64,8 +64,8 @@ class PythonCodeExecution(QObject):
:param user_locals: A mutable mapping type to store local variables :param user_locals: A mutable mapping type to store local variables
:returns: The created async task :returns: The created async task
""" """
# Stack is chopped on error to avoid the AsyncTask.run->_do_exec->exec calls appearing # Stack is chopped on error to avoid the AsyncTask.run->self.execute calls appearing
# as these are not useful in this context # as these are not useful for the user in this context
t = AsyncTask(self.execute, args=(code_str,), t = AsyncTask(self.execute, args=(code_str,),
stack_chop=2, stack_chop=2,
success_cb=self._on_success, error_cb=self._on_error) success_cb=self._on_success, error_cb=self._on_error)
......
...@@ -101,6 +101,7 @@ class PythonFileInterpreterPresenter(QObject): ...@@ -101,6 +101,7 @@ class PythonFileInterpreterPresenter(QObject):
self.model = model self.model = model
# offset of executing code from start of the file # offset of executing code from start of the file
self._code_start_offset = 0 self._code_start_offset = 0
self._is_executing = False
self._error_formatter = ErrorFormatter() self._error_formatter = ErrorFormatter()
# connect signals # connect signals
...@@ -111,7 +112,18 @@ class PythonFileInterpreterPresenter(QObject): ...@@ -111,7 +112,18 @@ class PythonFileInterpreterPresenter(QObject):
# starts idle # starts idle
self.view.set_status_message(IDLE_STATUS_MSG) self.view.set_status_message(IDLE_STATUS_MSG)
@property
def is_executing(self):
return self._is_executing
@is_executing.setter
def is_executing(self, value):
self._is_executing = value
def req_execute_async(self): def req_execute_async(self):
if self.is_executing:
return
self.is_executing = True
code_str, self._code_start_offset = self._get_code_for_execution() code_str, self._code_start_offset = self._get_code_for_execution()
if not code_str: if not code_str:
return return
...@@ -130,9 +142,7 @@ class PythonFileInterpreterPresenter(QObject): ...@@ -130,9 +142,7 @@ class PythonFileInterpreterPresenter(QObject):
return code_str, line_from return code_str, line_from
def _on_exec_success(self, task_result): def _on_exec_success(self, task_result):
self.view.set_editor_readonly(False) self._finish(success=True, elapsed_time=task_result.elapsed_time)
self.view.set_status_message(self._create_status_msg('successfully',
task_result.elapsed_time))
def _on_exec_error(self, task_error): def _on_exec_error(self, task_error):
exc_type, exc_value, exc_stack = task_error.exc_type, task_error.exc_value, \ exc_type, exc_value, exc_stack = task_error.exc_type, task_error.exc_value, \
...@@ -143,9 +153,14 @@ class PythonFileInterpreterPresenter(QObject): ...@@ -143,9 +153,14 @@ class PythonFileInterpreterPresenter(QObject):
lineno = exc_stack[-1][1] lineno = exc_stack[-1][1]
sys.stderr.write(self._error_formatter.format(exc_type, exc_value, exc_stack) + '\n') sys.stderr.write(self._error_formatter.format(exc_type, exc_value, exc_stack) + '\n')
self.view.editor.updateProgressMarker(lineno, True) self.view.editor.updateProgressMarker(lineno, True)
self._finish(success=False, elapsed_time=task_error.elapsed_time)
def _finish(self, success, elapsed_time):
status = 'successfully' if success else 'with errors'
self.view.set_status_message(self._create_status_msg(status,
elapsed_time))
self.view.set_editor_readonly(False) self.view.set_editor_readonly(False)
self.view.set_status_message(self._create_status_msg('with errors', self.is_executing = False
task_error.elapsed_time))
def _create_status_msg(self, status, elapsed_time): def _create_status_msg(self, status, elapsed_time):
return IDLE_STATUS_MSG + ' ' + \ return IDLE_STATUS_MSG + ' ' + \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment