Skip to content

Update _core.py#110

Merged
em92 merged 2 commits into
MinoMino:masterfrom
mgaertne:patch-2
Mar 19, 2023
Merged

Update _core.py#110
em92 merged 2 commits into
MinoMino:masterfrom
mgaertne:patch-2

Conversation

@mgaertne

Copy link
Copy Markdown
Contributor

added an exception hook for threads forwarding the relevant parameters to minqlx.handle_exception in order to have errors from threads logged in the logfile as well.

added an exception hook for threads forwarding the relevant parameters to minqlx.handle_exception in order to have errors from threads logged in the logfile as well.
@em92

em92 commented Apr 23, 2022

Copy link
Copy Markdown
Collaborator

Hi, Markus!
Using this plugin:

import minqlx
from time import sleep


class test(minqlx.Plugin):
    def __init__(self):
        self.add_hook("new_game", self.handle_new_game)

    def handle_new_game(self):
        @minqlx.delay(2)
        def f():
            raise NotImplementedError("test")

        f()

Info about exception appears in logfile without patch in this PR. What is your use-case?

Also, could you please remove those whitespaces? That are marked as red?
Снимок экрана_2022-04-23_10-50-26

@mgaertne

mgaertne commented Apr 23, 2022 via email

Copy link
Copy Markdown
Contributor Author

removed unnecessary whitespaces
@mgaertne

Copy link
Copy Markdown
Contributor Author

To reproduce use the following plugin:

import minqlx


class exception_thread(minqlx.Plugin):
    def __init__(self):
        super().__init__()

        self.add_command("exception_thread", self.cmd_exception_thread)

    def cmd_exception_thread(self, _player: minqlx.Player, _cmd: str, _channel: minqlx.AbstractChannel):
        @minqlx.thread
        def throws_exception():
            self.logger.debug("about to throw exception in thread...")
            raise NotImplementedError("Test")

        self.logger.debug("about to start exception thread...")
        throws_exception()
        self.logger.debug("exception thread started...")

output before updating _core.py:

(19:31:22) [DEBUG @ minqlx.exception_thread.cmd_exception_thread] about to start exception thread...
(19:31:22) [DEBUG @ minqlx.exception_thread.throws_exception] about to throw exception in thread...
(19:31:22) [DEBUG @ minqlx.exception_thread.cmd_exception_thread] exception thread started...

output after updating _core.py:

(19:36:04) [DEBUG @ minqlx.exception_thread.cmd_exception_thread] about to start exception thread...
(19:36:04) [DEBUG @ minqlx.exception_thread.throws_exception] about to throw exception in thread...
(19:36:04) [DEBUG @ minqlx.exception_thread.cmd_exception_thread] exception thread started...
(19:36:04) [ERROR @ minqlx.handle_exception] Traceback (most recent call last):
(19:36:04) [ERROR @ minqlx.handle_exception]   File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
(19:36:04) [ERROR @ minqlx.handle_exception]     self.run()
(19:36:04) [ERROR @ minqlx.handle_exception]   File "/usr/lib/python3.9/threading.py", line 892, in run
(19:36:04) [ERROR @ minqlx.handle_exception]     self._target(*self._args, **self._kwargs)
(19:36:04) [ERROR @ minqlx.handle_exception]   File "./minqlx-plugins/exception_thread.py", line 14, in throws_exception
(19:36:04) [ERROR @ minqlx.handle_exception]     raise NotImplementedError("Test")
(19:36:04) [ERROR @ minqlx.handle_exception] NotImplementedError: Test

@em92 em92 merged commit c93838a into MinoMino:master Mar 19, 2023
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