open-cogsci / OpenSesame

Graphical experiment builder for the social sciences
http://osdoc.cogsci.nl/
GNU General Public License v3.0
234 stars 111 forks source link

`NameError` due to missing gettext `_` builtin occurs (seemingly) randomly #762

Closed mirh closed 3 years ago

mirh commented 3 years ago

I was doing basically nothing with your basic starting example, when this happened:

Traceback (most recent call last):
  File "..\opensesame_3.3.9-py37-win64-2\Lib\site-packages\libqtopensesame\items\qtitem.py", line 433, in set_view_script
    self.init_script_widget()
  File "..\opensesame_3.3.9-py37-win64-2\Lib\site-packages\libqtopensesame\items\qtitem.py", line 63, in inner
    retval = fnc(self, *args, **kwargs)
  File "..\opensesame_3.3.9-py37-win64-2\Lib\site-packages\libqtopensesame\items\qtitem.py", line 339, in init_script_widget
    self._script_widget = OpenSesameCodeEdit(self.main_window)
  File "..\opensesame_3.3.9-py37-win64-2\share\opensesame_extensions\pyqode_manager\pyqode_extras\widgets\text_code_edit.py", line 49, in __init__
    super(TextCodeEdit, self).__init__(parent)
  File "..\opensesame_3.3.9-py37-win64-2\Lib\site-packages\pyqode\core\api\code_edit.py", line 493, in __init__
    self._init_actions(create_default_actions)
  File "..\opensesame_3.3.9-py37-win64-2\Lib\site-packages\pyqode\core\api\code_edit.py", line 1248, in _init_actions
    menu_advanced = QtWidgets.QMenu(_('Advanced'), self)
NameError: name '_' is not defined

And then every time the tab tried to restart (I think it was a sketchpad, but I could be wrong), I got this in an infinite loop:

Traceback (most recent call last):
  File "..\opensesame_3.3.9-py37-win64-2\Lib\site-packages\pyqode\core\managers\backend.py", line 284, in _send_heartbeat
    self.send_request(echo_worker, {'heartbeat': True})
  File "..\opensesame_3.3.9-py37-win64-2\Lib\site-packages\pyqode\core\managers\backend.py", line 251, in send_request
    if not BackendManager.SHARE_COUNT.get(self._share_id, []):
AttributeError: 'BackendManager' object has no attribute '_share_id'
smathot commented 3 years ago

Thanks for reporting this. I've seen this error myself too, but it's very hard to reproduce. Are you able to reproduce it reliably? If so, what are the steps? And a few questions to narrow the issue down:

mirh commented 3 years ago

Aren't they two separate issues? Like, maybe I'm just too much of a python noob, but I don't see "_share_id" (or SHARE_COUNT) defined anywhere else in the project or its dependencies but the part where it crashes because it cannot find it. ... did you actually ever verified the auto restart feature?

Anyway I had literally just unpacked the program and run it for the first (or second at most?) time. I cannot really remember much details since I was already overloaded with tasks to keep in mind in a conference.

AFAICT I didn't change any setting, except perhaps font size (Idk if I did this sooner or later, and I went from 14pt to 12pt because other wise words were pretty huge with 125% HiDPI scaling) Console and runner are multiprocess and python.

smathot commented 3 years ago

The error can be reproduced with the following steps:

  1. Open the default template
  2. Open the getting_started item.
  3. In the in-process Python console, run del __builtins__._
  4. Open the welcome sketchpad and try to view the script.

Possibly, some library deletes _ from the built-ins, although it's not clear to me which library does this and why. In any case, re-installing _ before step 4 (per the script below) fixes the issues. A potential fix might therefore be to check whether _ exists before initializing a new code editor, and if not re-install it explicitly.

import gettext
gettext.NullTranslations().install()

Aren't they two separate issues?

They are related. The second AttributeError is a consequence of the first NameError, which prevents the code editor from initializing.

smathot commented 3 years ago

I just experienced it for the first time also on Ubuntu (so apparently it's not Windows-specific). This happens consistently after just opening OpenSesame and then going to the backend settings.

Traceback (most recent call last):
  File "/usr/share/opensesame_extensions/preload_items/preload_items.py", line 73, in _on_awake
    self._preload_one_item()
  File "/usr/share/opensesame_extensions/preload_items/preload_items.py", line 87, in _preload_one_item
    item.init_edit_widget()
  File "/usr/lib/python3/dist-packages/libqtopensesame/items/qtautoplugin.py", line 112, in init_edit_widget
    widget = self.add_editor_control(c[u'var'], c[u'label'],
  File "/usr/lib/python3/dist-packages/libqtopensesame/items/qtplugin.py", line 425, in add_editor_control
    editor = CodeEdit(self.main_window)
  File "/usr/share/opensesame_extensions/pyqode_manager/pyqode_extras/widgets/text_code_edit.py", line 49, in __init__
    super(TextCodeEdit, self).__init__(parent)
  File "/usr/lib/python3/dist-packages/pyqode/core/api/code_edit.py", line 493, in __init__
    self._init_actions(create_default_actions)
  File "/usr/lib/python3/dist-packages/pyqode/core/api/code_edit.py", line 1248, in _init_actions
    menu_advanced = QtWidgets.QMenu(_('Advanced'), self)
NameError: name '_' is not defined