[Python] Python asyncio/Telethon script suddenly stopped working after VSCode restart (Python...

Discussão em 'Python' iniciado por Stack, Julho 19, 2025.

  1. Stack

    Stack Membro Participativo

    I have a Python script using asyncio (for Telethon) and until recently, it was running just fine in a Terminal inside VSCode.

    However, an extension install prompted a VSCode restart and now I can't get my code to run anymore, even though the code files themselves haven't changed.

    It seems that Telethon fails to initialise, and the problem doesn't seem to be with the Telethon database file, as I also tried renaming the DB file and starting my code which leads to the same error message.

    I tried updating Telethon using pip, but the error remains.

    The error I'm getting is:

    Traceback (most recent call last):
    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 261, in _add_reader
    key = self._selector.get_key(fd)
    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/selectors.py", line 193, in get_key
    raise KeyError("{!r} is not registered".format(fileobj)) from None
    KeyError: '6 is not registered'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/Users/sora/Documents/*******/*******-scraper-redeemer-dist.py", line 36, in <module>
    client = TelegramClient("*******-scraper", api_id, api_hash)
    File "/Users/sora/Library/Python/3.9/lib/python/site-packages/telethon/client/telegrambaseclient.py", line 339, in __init__
    if not callable(getattr(self.loop, 'sock_connect', None)):
    File "/Users/sora/Library/Python/3.9/lib/python/site-packages/telethon/client/telegrambaseclient.py", line 488, in loop
    return helpers.get_running_loop()
    File "/Users/sora/Library/Python/3.9/lib/python/site-packages/telethon/helpers.py", line 432, in get_running_loop
    return asyncio.get_event_loop_policy().get_event_loop()
    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/events.py", line 639, in get_event_loop
    self.set_event_loop(self.new_event_loop())
    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/events.py", line 659, in new_event_loop
    return self._loop_factory()
    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/unix_events.py", line 54, in __init__
    super().__init__(selector)
    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 61, in __init__
    self._make_self_pipe()
    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 112, in _make_self_pipe
    self._add_reader(self._ssock.fileno(), self._read_from_self)
    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 263, in _add_reader
    self._selector.register(fd, selectors.EVENT_READ,
    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/selectors.py", line 523, in register
    self._selector.control([kev], 0, 0)
    TypeError: changelist must be an iterable of select.kevent objects
    Exception ignored in: <function BaseEventLoop.__del__ at 0x103a88ee0>
    Traceback (most recent call last):
    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 683, in __del__
    self.close()
    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/unix_events.py", line 63, in close
    if self._signal_handlers:
    AttributeError: '_UnixSelectorEventLoop' object has no attribute '_signal_handlers'


    Maybe some of you have experienced this error before and can help me pinpoint the problem.

    Continue reading...

Compartilhe esta Página