Support having no sys.argv in debugger. Fixes #473

This commit is contained in:
Fabio Zadrozny 2020-12-10 10:19:12 -03:00
parent 93516395a9
commit e573ea771a
3 changed files with 16 additions and 10 deletions

View file

@ -400,8 +400,9 @@ class PyDevJsonCommandProcessor(object):
self.api.stop_on_entry()
def _send_process_event(self, py_db, start_method):
if len(sys.argv) > 0:
name = sys.argv[0]
argv = getattr(sys, 'argv', [])
if len(argv) > 0:
name = argv[0]
else:
name = ''

View file

@ -38,10 +38,12 @@ GUI_NONE = 'none' # i.e. disable
# Utilities
#-----------------------------------------------------------------------------
def ignore_CTRL_C():
"""Ignore CTRL+C (not implemented)."""
pass
def allow_CTRL_C():
"""Take CTRL+C into account (not implemented)."""
pass
@ -297,7 +299,6 @@ class InputHookManager(object):
"""
self.clear_inputhook()
def enable_glut(self, app=None):
""" Enable event loop integration with GLUT.
@ -329,13 +330,14 @@ class InputHookManager(object):
glut_idle, inputhook_glut
if GUI_GLUT not in self._apps:
glut.glutInit(sys.argv)
argv = getattr(sys, 'argv', [])
glut.glutInit(argv)
glut.glutInitDisplayMode(glut_display_mode)
# This is specific to freeglut
if bool(glut.glutSetOption):
glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE,
glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS)
glut.glutCreateWindow(sys.argv[0])
glut.glutCreateWindow(argv[0] if len(argv) > 0 else '')
glut.glutReshapeWindow(1, 1)
glut.glutHideWindow()
glut.glutWMCloseFunc(glut_close)
@ -349,7 +351,6 @@ class InputHookManager(object):
self._current_gui = GUI_GLUT
self._apps[GUI_GLUT] = True
def disable_glut(self):
"""Disable event loop integration with glut.
@ -430,6 +431,7 @@ class InputHookManager(object):
possible to choose backend before importing pyplot for the first
time only.
"""
def inputhook_mac(app=None):
if self.pyplot_imported:
pyplot = sys.modules['matplotlib.pyplot']
@ -451,6 +453,7 @@ class InputHookManager(object):
"""Return a string indicating the currently active GUI or None."""
return self._current_gui
inputhook_manager = InputHookManager()
enable_wx = inputhook_manager.enable_wx
@ -484,6 +487,7 @@ set_return_control_callback = inputhook_manager.set_return_control_callback
get_return_control_callback = inputhook_manager.get_return_control_callback
get_inputhook = inputhook_manager.get_inputhook
# Convenience function to switch amongst them
def enable_gui(gui=None, app=None):
"""Switch amongst GUI input hooks by name.
@ -535,6 +539,7 @@ def enable_gui(gui=None, app=None):
raise ValueError(e)
return gui_hook(app)
__all__ = [
"GUI_WX",
"GUI_QT",
@ -548,7 +553,6 @@ __all__ = [
"GUI_GTK3",
"GUI_NONE",
"ignore_CTRL_C",
"allow_CTRL_C",

View file

@ -3,13 +3,14 @@ if __name__ == '__main__':
import sys
port = int(sys.argv[1])
root_dirname = os.path.dirname(os.path.dirname(__file__))
if root_dirname not in sys.path:
sys.path.append(root_dirname)
del sys.argv
import pydevd
print('before pydevd.settrace')
pydevd.settrace(port=port)
print('after pydevd.settrace')
print('TEST SUCEEDED!')