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

Convert PyQt5 to local import in tribler common #5852

Merged
merged 2 commits into from
Dec 17, 2020

Conversation

xoriole
Copy link
Contributor

@xoriole xoriole commented Dec 14, 2020

Tribler common is required by the core where it is best not to include PyQt dependency. I had an issue finding & resolving all required dependencies of PyQt5 while running in headless mode.

devos50
devos50 previously approved these changes Dec 14, 2020
Copy link
Contributor

@ichorid ichorid left a comment

Choose a reason for hiding this comment

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

Maybe add try..except here on imports?

@xoriole
Copy link
Contributor Author

xoriole commented Dec 15, 2020

@ichorid thought about using try..except but normally the function and the import would not be called if there is no exception so local import should be ok.

@ichorid
Copy link
Contributor

ichorid commented Dec 15, 2020

@ichorid thought about using try..except but normally the function and the import would not be called if there is no exception so local import should be ok.

So, there is gonna be a crash on exception if local import will not work?

@xoriole
Copy link
Contributor Author

xoriole commented Dec 15, 2020

So, there is gonna be a crash on exception if local import will not work?

Yes, it should. Note that in the enclosing function call, we're trying to trying to ask user consent to send the exception/crash report to sentry. If there is no PyQt5, we cannot (should not) send error report silently without user consent so in my opinion it is best to just crash there if that happens.

@staticmethod
def get_confirmation(exception):
"""Get confirmation on sending exception to the Team.
There are two message boxes, that will be triggered:
1. Message box with the error_text
2. Message box with confirmation about sending this report to the Tribler
team.
Args:
exception: exception to be sent.
"""
# Prevent importing PyQt globally in tribler-common module.
# pylint: disable=import-outside-toplevel
from PyQt5.QtWidgets import QApplication, QMessageBox
SentryReporter._logger.debug(f"Get confirmation: {exception}")
_ = QApplication(sys.argv)
messagebox = QMessageBox(icon=QMessageBox.Critical, text=f'{exception}.')
messagebox.setWindowTitle("Error")
messagebox.exec()
messagebox = QMessageBox(
icon=QMessageBox.Question,
text='Do you want to send this crash report to the Tribler team? '
'We anonymize all your data, who you are and what you downloaded.',
)
messagebox.setWindowTitle("Error")
messagebox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
return messagebox.exec() == QMessageBox.Yes

@ichorid
Copy link
Contributor

ichorid commented Dec 15, 2020

If there is no PyQt5, we cannot (should not) send error report silently without user consent so in my opinion it is best to just crash there if that happens.

OK. The Core would gonna crash anyway, so why not?

@xoriole
Copy link
Contributor Author

xoriole commented Dec 16, 2020

Some observation based on the current state of the code and error reporting

  1. If there is an unhandled exception in the core, the strategy used is Strategy.SEND_SUPPRESSED. That means it will not ask for confirmation, rather the event is stored and dropped. Therefore the above code is never executed.

  2. Even if the strategy is set to Strategy.SEND_ALLOWED_WITH_CONFIRMATION where a user confirmation is expected. I still do not see import error in the logs. For example, introducing a runtime error in torrent checker produces the following logs:

[PID:12223] 2020-12-16 13:33:16,475 - ERROR <session:250> Session.unhandled_error_observer(): Unhandled exception occurred! Raising an error intentionally
--LONG TEXT--
Traceback (most recent call last):
  File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
  File "/home/jupiter/tudelft/release/tribler/src/pyipv8/ipv8/taskmanager.py", line 131, in done_cb
    future.result()
  File "/home/jupiter/tudelft/release/tribler/src/pyipv8/ipv8/taskmanager.py", line 18, in interval_runner
    await task(*args)
  File "/home/jupiter/tudelft/release/tribler/src/pyipv8/ipv8/util.py", line 35, in call_async
    return func(*args, **kwargs)
  File "<string>", line 2, in check_random_torrent
  File "/home/jupiter/.local/lib/python3.8/site-packages/pony/orm/core.py", line 528, in new_func
    result = func(*args, **kwargs)
  File "/home/jupiter/tudelft/release/tribler/src/tribler-core/tribler_core/modules/torrent_checker/torrent_checker.py", line 162, in check_random_torrent
    raise RuntimeError("Raising an error intentionally")
RuntimeError: Raising an error intentionally

--CONTEXT--
{'message': "Exception in callback TaskManager.register_task.<locals>.done_cb(<Task finishe...tentionally')>) at /home/jupiter/tudelft/release/tribler/src/pyipv8/ipv8/taskmanager.py:128", 'exception': RuntimeError('Raising an error intentionally'), 'handle': <Handle TaskManager.register_task.<locals>.done_cb(<Task finishe...tentionally')>) at /home/jupiter/tudelft/release/tribler/src/pyipv8/ipv8/taskmanager.py:128>}
[PID:12223] 2020-12-16 13:33:16,478 - INFO - SentryReporter(252) - Event from exception: Raising an error intentionally
[PID:12223] 2020-12-16 13:33:16,492 - INFO - SentryReporter(314) - Before send strategy: Strategy.SEND_ALLOWED_WITH_CONFIRMATION
[PID:12223] 2020-12-16 13:33:16,732 - INFO - TriblerTunnelCommunity(312) - Sending payout of 0 (base: 0) to Peer<81.171.8.17:35195, W8pxSwFeatcJq63LE1uXsAaxC8g=> (cid: 3912062244)
[PID:12223] 2020-12-16 13:33:16,747 - INFO - TriblerTunnelCommunity(319) - Removing DATA circuit 3912062244 timeout, 5 tries left

It was expected that import error would mask the actual error but not really (strange).

@drew2a drew2a linked an issue Dec 16, 2020 that may be closed by this pull request
@xoriole xoriole requested a review from ichorid December 16, 2020 15:27
drew2a
drew2a previously approved these changes Dec 17, 2020
Tribler common is required by the core where it is
best not to include PyQt dependency.
@sonarcloud
Copy link

sonarcloud bot commented Dec 17, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.7% 0.7% Duplication

@xoriole xoriole merged commit f068b0f into Tribler:devel Dec 17, 2020
@xoriole xoriole deleted the fix/qt_import branch August 4, 2021 08:48
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.

[devel] Core is importing from PyQt5
4 participants