﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	blockedby	blocking	notify_on_close	platform	project
4460	Python script on startup command-line, QTimer errors	Tom Goddard	Eric Pettersen	"If I start ChimeraX from a shell with a Python script argument and the Python script raises an error I get a hard to follow traceback where the actual error is listed followed by about 6 QTimer errors and ChimeraX fails to start.

Should give just the error that actually occurred in the script, and also ChimeraX should probably remain running.

Here's my example Python test.py script.  ChimeraX apparently does not keep the __file__ variable in the script global namespace so it raises an error.

print ('starting test.py with __file__ = ', __file__)


$ ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/MacOS/ChimeraX"" test.py
""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/MacOS/ChimeraX"" test.py
Traceback (most recent call last):
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ChimeraX_main.py"", line 813, in init
    commands.run(sess, 'open %s' % StringArg.unparse(arg))
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/commands/run.py"", line 36, in run
    results = command.run(text, log=log, return_json=return_json)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/commands/cli.py"", line 2852, in run
    result = ci.function(session, **kw_args)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/open_command/cmd.py"", line 118, in cmd_open
    models = Command(session, registry=registry).run(provider_cmd_text, log=log)[0]
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/commands/cli.py"", line 2852, in run
    result = ci.function(session, **kw_args)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/open_command/cmd.py"", line 179, in provider_open
    models, status = collated_open(session, None, [data], data_format, _add_models,
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/open_command/cmd.py"", line 404, in collated_open
    return func(*func_args, **func_kw)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core_formats/__init__.py"", line 48, in open
    return open_python_script(session, data, file_name)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/scripting.py"", line 82, in open_python_script
    _exec_python(session, code, argv)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/scripting.py"", line 59, in _exec_python
    exec(code, sandbox.__dict__)
  File ""test.py"", line 1, in <module>
    print ('starting test.py with __file__ = ', __file__)
NameError: name '__file__' is not defined
Error in sys.excepthook:
Traceback (most recent call last):
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 297, in ehook
    self.session.ui.thread_safe(self.report_exception, exc_info=exc_info)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/ui/gui.py"", line 363, in thread_safe
    func(*args, **kw)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 443, in report_exception
    self.info(tb_msg, is_html=True)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 388, in info
    self._log(Log.LEVEL_INFO, msg, add_newline, image, is_html,
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 498, in _log
    if log.log(*args):
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 340, in log
    self.show_page_source()
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 344, in show_page_source
    self.session.ui.thread_safe(self._show)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/ui/gui.py"", line 363, in thread_safe
    func(*args, **kw)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 348, in _show
    self.regulating_timer.start(100)
RuntimeError: wrapped C/C++ object of type QTimer has been deleted

Original exception was:
Traceback (most recent call last):
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/ui/gui.py"", line 202, in cx_qt_msg_handler
    self.session.logger.method_map[log_level](msg_string)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 465, in warning
    self._log(Log.LEVEL_WARNING, msg, add_newline, image, is_html,
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 498, in _log
    if log.log(*args):
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 340, in log
    self.show_page_source()
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 344, in show_page_source
    self.session.ui.thread_safe(self._show)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/ui/gui.py"", line 363, in thread_safe
    func(*args, **kw)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 348, in _show
    self.regulating_timer.start(100)
RuntimeError: wrapped C/C++ object of type QTimer has been deleted
Error in sys.excepthook:
Traceback (most recent call last):
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 297, in ehook
    self.session.ui.thread_safe(self.report_exception, exc_info=exc_info)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/ui/gui.py"", line 363, in thread_safe
    func(*args, **kw)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 443, in report_exception
    self.info(tb_msg, is_html=True)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 388, in info
    self._log(Log.LEVEL_INFO, msg, add_newline, image, is_html,
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 498, in _log
    if log.log(*args):
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 340, in log
    self.show_page_source()
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 344, in show_page_source
    self.session.ui.thread_safe(self._show)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/ui/gui.py"", line 363, in thread_safe
    func(*args, **kw)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 348, in _show
    self.regulating_timer.start(100)
RuntimeError: wrapped C/C++ object of type QTimer has been deleted

Original exception was:
Traceback (most recent call last):
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/ui/gui.py"", line 202, in cx_qt_msg_handler
    self.session.logger.method_map[log_level](msg_string)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 465, in warning
    self._log(Log.LEVEL_WARNING, msg, add_newline, image, is_html,
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 498, in _log
    if log.log(*args):
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 340, in log
    self.show_page_source()
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 344, in show_page_source
    self.session.ui.thread_safe(self._show)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/ui/gui.py"", line 363, in thread_safe
    func(*args, **kw)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 348, in _show
    self.regulating_timer.start(100)
RuntimeError: wrapped C/C++ object of type QTimer has been deleted
Error in sys.excepthook:
Traceback (most recent call last):
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 297, in ehook
    self.session.ui.thread_safe(self.report_exception, exc_info=exc_info)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/ui/gui.py"", line 363, in thread_safe
    func(*args, **kw)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 443, in report_exception
    self.info(tb_msg, is_html=True)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 388, in info
    self._log(Log.LEVEL_INFO, msg, add_newline, image, is_html,
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 498, in _log
    if log.log(*args):
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 340, in log
    self.show_page_source()
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 344, in show_page_source
    self.session.ui.thread_safe(self._show)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/ui/gui.py"", line 363, in thread_safe
    func(*args, **kw)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 348, in _show
    self.regulating_timer.start(100)
RuntimeError: wrapped C/C++ object of type QTimer has been deleted

Original exception was:
Traceback (most recent call last):
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/ui/gui.py"", line 202, in cx_qt_msg_handler
    self.session.logger.method_map[log_level](msg_string)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 465, in warning
    self._log(Log.LEVEL_WARNING, msg, add_newline, image, is_html,
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/core/logger.py"", line 498, in _log
    if log.log(*args):
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 340, in log
    self.show_page_source()
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 344, in show_page_source
    self.session.ui.thread_safe(self._show)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/ui/gui.py"", line 363, in thread_safe
    func(*args, **kw)
  File ""/Users/goddard/Desktop/ChimeraX April 1 2021.app/Contents/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chimerax/log/tool.py"", line 348, in _show
    self.regulating_timer.start(100)
RuntimeError: wrapped C/C++ object of type QTimer has been deleted
"	defect	closed	moderate		Logging		fixed						all	ChimeraX
