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
NameError: name 'BRIDGE' is not defined #15
Comments
Can you the event-loop-fix branch to see if it fixes the issue? |
Right, I think I figured it out - looks like it was because I installed everything in a virtualenv. |
Mirage is crashing for me as well and I get a somewhat similar traceback; I didn't think it warranted its own issue because it looks like the core problem is the same. I installed it with the AUR package.
|
Can you post the output of these?
And in
Then start mirage with:
|
I got the error mentioned in the original report and also had some Python packages installed in virtualenv (those not available in Debian unstable). I'm not sure how virtualenv affects it, but there seems to be something funny about threads. Apparently the Python bridge thread is not the main application thread so the asyncio module does not install a default event loop. I was able to fix it with:
However I'm then getting a bunch of various QML errors and messages are not displayed, but I think that's a different issue. |
The error shouldn't be the same unless you run an old version of Mirage, can you post the full traceback? |
QMLBridge.init does not explicitly create an asyncio event loop; it relies on get_event_loop implicitly creating one. According to the documentation that only happens if the OS thread is main, which apparently is not the case here. Using strace I can see that the process starts with pid 24064 but the exception gets printed from pid 24066. Furthermore, as can be seen in the traceback, a few calls down from the import Backend line there's an attempt to create a semaphore, which wants to attach itself to the event loop of the current thread. This happens before even the get_event_loop call in QMLBridge.init. My patch attempts to do the same get_event_loop() call and if it doesn't succeed, it explicitly creates a new event loop and sets it for the current thread. The exact placement of these lines does not really matter as long as they happen before the import Backend call. Here's an alternative version:
My version of Mirage is git version from Monday, with HEAD at 8b8829a. |
You're right, I didn't even notice the In any case, if your issue #35 is fixed, is everything working with your patch? Will you make a PR, or should I just add the changes myself? |
Depending on Python version the file may be imported in a thread and asyncio only implicitly creates an event loop in the main thread of the process. Backend does things which need asyncio so we must ensure an event loop exists before it is imported. Fixes mirukana#15
I haven't tried any advanced features yet but now that I got #35 fixed I can at least get a working UI and view channels. |
I just updated my arch linux, and mirage just broke with this exact error message. What broke? |
Here is full log from starting mirage with the command ~ 11:04:06 | Got library name: "/usr/lib/qt/qml/io/thp/pyotherside/libpyo
~ 11:04:07 | "PyOtherSide error: Traceback (most recent call last):\n\n File \"qrc:/src/backend/qml_bridge.py\", line 176, in <module>\n BRIDGE = QMLBridge()\n\n File \"qrc:/src/backend/qml_bridge.py\", line 53, in __init__\n from .backend import Backend\n\n File \"qrc:/src/backend/backend.py\", line 17, in <module>\n from .matrix_client import MatrixClient\n\n File \"qrc:/src/backend/matrix_client.py\", line 42, in <module>\n from .html_markdown import HTML_PROCESSOR as HTML\n\n File \"qrc:/src/backend/html_markdown.py\", line 9, in <module>\n import html_sanitizer.sanitizer as sanitizer\n\nModuleNotFoundError: No module named 'html_sanitizer'\n"
! 11:04:07 | Unhandled PyOtherSide error: Cannot import module: backend.qml_bridge (Traceback (most recent call last):
File "qrc:/src/backend/qml_bridge.py", line 176, in <module>
BRIDGE = QMLBridge()
File "qrc:/src/backend/qml_bridge.py", line 53, in __init__
from .backend import Backend
File "qrc:/src/backend/backend.py", line 17, in <module>
from .matrix_client import MatrixClient
File "qrc:/src/backend/matrix_client.py", line 42, in <module>
from .html_markdown import HTML_PROCESSOR as HTML
File "qrc:/src/backend/html_markdown.py", line 9, in <module>
import html_sanitizer.sanitizer as sanitizer
ModuleNotFoundError: No module named 'html_sanitizer'
)
~ 11:04:07 | "PyOtherSide error: Traceback (most recent call last):\n\n File \"<string>\", line 1, in <module>\n\nNameError: name 'BRIDGE' is not defined\n"
! 11:04:07 | Unhandled PyOtherSide error: Function not found: 'BRIDGE.call_backend_coro' (Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'BRIDGE' is not defined
)
I am on arch linux, and I guess an update with python somewhere changed some python sym links ( weird python version sym linking ) I reinstalled |
Running
mirage
right after installing it on my Archlinux setup causes an infinite spinner and prints the following in the following to be printed in the terminal:The text was updated successfully, but these errors were encountered: