Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for race condition by loading text only after the editor has been loaded #37

Merged

Conversation

oreillysean
Copy link
Contributor

Hi

When running cupcake on my machine I was intermittently getting this error:

Traceback (most recent call last):
  File "/Users/sean/Documents/PycharmProjects/cupcake/cupcake/texteditor/text.py", line 294, in load_file
    self.process_queue()
  File "/Users/sean/Documents/PycharmProjects/cupcake/cupcake/texteditor/text.py", line 317, in process_queue
    self.master.on_scroll()
  File "/Users/sean/Documents/PycharmProjects/cupcake/cupcake/texteditor/__init__.py", line 46, in on_scroll
    self.linenumbers.redraw()
    ^^^^^^^^^^^^^^^^
AttributeError: 'TextEditor' object has no attribute 'linenumbers'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sean/Documents/PycharmProjects/cupcake/examples/basic.py", line 20, in <module>
    e = Editor(root, __file__)
        ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sean/Documents/PycharmProjects/cupcake/cupcake/__init__.py", line 99, in __init__
    self.content = get_editor(self, path, path2, diff, language)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sean/Documents/PycharmProjects/cupcake/cupcake/__init__.py", line 29, in get_editor
    return TextEditor(base, path, language=language)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sean/Documents/PycharmProjects/cupcake/cupcake/texteditor/__init__.py", line 21, in __init__
    self.text = Text(self, path=self.path, minimalist=minimalist, language=language)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sean/Documents/PycharmProjects/cupcake/cupcake/texteditor/text.py", line 27, in __init__
    self.load_file()
  File "/Users/sean/Documents/PycharmProjects/cupcake/cupcake/texteditor/text.py", line 296, in load_file
    self.master.unsupported_file()
  File "/Users/sean/Documents/PycharmProjects/cupcake/cupcake/texteditor/__init__.py", line 51, in unsupported_file
    self.text.highlighter.lexer = None
    ^^^^^^^^^
AttributeError: 'TextEditor' object has no attribute 'text'

I believe this is due to a race condition where a thread is spawned to load the text into the editor before the editor has been fully loaded. This attempts to fix that by moving the load operation into the end of the TextEditor class.

My os information

macOS Ventura
Version 13.4.1 (22F82)
Chip: Apple M2 Pro
Python 3.11.4

Copy link
Owner

@tomlin7 tomlin7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this! this part was really unnoticed and untested.

@tomlin7 tomlin7 merged commit c268266 into tomlin7:main Jul 27, 2023
tomlin7 added a commit to tomlin7/biscuit that referenced this pull request Jul 27, 2023
- merge cupcake updates
- consider tomlin7/cupcake#37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants