mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
Fix errors and fully support matplotlib interactive mode in run and debug with the option "Show command line afterwards" enabled (PY-21330)
This commit is contained in:
@@ -3,8 +3,7 @@ Entry point module to run a file in the interactive console.
|
||||
'''
|
||||
import os
|
||||
import sys
|
||||
from pydevconsole import do_exit, InterpreterInterface, process_exec_queue, start_console_server
|
||||
from _pydev_bundle.pydev_console_utils import BaseStdIn
|
||||
from pydevconsole import do_exit, InterpreterInterface, process_exec_queue, start_console_server, init_mpl_in_console
|
||||
from _pydev_imps._pydev_saved_modules import threading
|
||||
|
||||
from _pydev_bundle import pydev_imports
|
||||
@@ -74,6 +73,8 @@ if __name__ == '__main__':
|
||||
|
||||
sys.stdin = StdIn(interpreter, host, client_port, sys.stdin)
|
||||
|
||||
init_mpl_in_console(interpreter)
|
||||
|
||||
globals = run_file(file, None, None)
|
||||
|
||||
interpreter.get_namespace().update(globals)
|
||||
|
||||
@@ -155,9 +155,8 @@ def set_debug_hook(debug_hook):
|
||||
_ProcessExecQueueHelper._debug_hook = debug_hook
|
||||
|
||||
|
||||
def process_exec_queue(interpreter):
|
||||
|
||||
from pydev_ipython.inputhook import get_inputhook, set_return_control_callback
|
||||
def init_mpl_in_console(interpreter):
|
||||
from pydev_ipython.inputhook import set_return_control_callback
|
||||
|
||||
def return_control():
|
||||
''' A function that the inputhooks can call (via inputhook.stdin_ready()) to find
|
||||
@@ -187,6 +186,11 @@ def process_exec_queue(interpreter):
|
||||
import_hook_manager.add_module_name("pylab", activate_pylab)
|
||||
import_hook_manager.add_module_name("pyplot", activate_pyplot)
|
||||
|
||||
|
||||
def process_exec_queue(interpreter):
|
||||
init_mpl_in_console(interpreter)
|
||||
from pydev_ipython.inputhook import get_inputhook
|
||||
|
||||
while 1:
|
||||
# Running the request may have changed the inputhook in use
|
||||
inputhook = get_inputhook()
|
||||
|
||||
@@ -400,6 +400,23 @@ class PyDB:
|
||||
"matplotlib.pyplot": activate_pyplot,
|
||||
"pylab": activate_pylab }
|
||||
|
||||
def _activate_mpl_if_needed(self):
|
||||
if len(self.mpl_modules_for_patching) > 0:
|
||||
for module in dict_keys(self.mpl_modules_for_patching):
|
||||
if module in sys.modules:
|
||||
activate_function = dict_pop(self.mpl_modules_for_patching, module)
|
||||
activate_function()
|
||||
self.mpl_in_use = True
|
||||
|
||||
def _call_mpl_hook(self):
|
||||
try:
|
||||
from pydev_ipython.inputhook import get_inputhook
|
||||
inputhook = get_inputhook()
|
||||
if inputhook:
|
||||
inputhook()
|
||||
except:
|
||||
pass
|
||||
|
||||
def suspend_all_other_threads(self, thread_suspended_at_bp):
|
||||
all_threads = threadingEnumerate()
|
||||
for t in all_threads:
|
||||
@@ -716,30 +733,16 @@ class PyDB:
|
||||
finally:
|
||||
CustomFramesContainer.custom_frames_lock.release() # @UndefinedVariable
|
||||
|
||||
imported = False
|
||||
info = thread.additional_info
|
||||
|
||||
if info.pydev_state == STATE_SUSPEND and not self._finish_debugging_session:
|
||||
# before every stop check if matplotlib modules were imported inside script code
|
||||
if len(self.mpl_modules_for_patching) > 0:
|
||||
for module in dict_keys(self.mpl_modules_for_patching):
|
||||
if module in sys.modules:
|
||||
activate_function = dict_pop(self.mpl_modules_for_patching, module)
|
||||
activate_function()
|
||||
self.mpl_in_use = True
|
||||
self._activate_mpl_if_needed()
|
||||
|
||||
while info.pydev_state == STATE_SUSPEND and not self._finish_debugging_session:
|
||||
if self.mpl_in_use:
|
||||
# call input hooks if only matplotlib is in use
|
||||
try:
|
||||
if not imported:
|
||||
from pydev_ipython.inputhook import get_inputhook
|
||||
imported = True
|
||||
inputhook = get_inputhook()
|
||||
if inputhook:
|
||||
inputhook()
|
||||
except:
|
||||
pass
|
||||
self._call_mpl_hook()
|
||||
|
||||
self.process_internal_commands()
|
||||
time.sleep(0.01)
|
||||
@@ -979,6 +982,8 @@ class PyDB:
|
||||
self.writer.add_command(cmd)
|
||||
|
||||
def wait_for_commands(self, globals):
|
||||
self._activate_mpl_if_needed()
|
||||
|
||||
thread = threading.currentThread()
|
||||
from _pydevd_bundle import pydevd_frame_utils
|
||||
frame = pydevd_frame_utils.Frame(None, -1, pydevd_frame_utils.FCode("Console",
|
||||
@@ -991,6 +996,9 @@ class PyDB:
|
||||
self.writer.add_command(cmd)
|
||||
|
||||
while True:
|
||||
if self.mpl_in_use:
|
||||
# call input hooks if only matplotlib is in use
|
||||
self._call_mpl_hook()
|
||||
self.process_internal_commands()
|
||||
time.sleep(0.01)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user