AREPL-vscode icon indicating copy to clipboard operation
AREPL-vscode copied to clipboard

Sorry, AREPL has ran into an error - probably macOS

Open jbarlow83 opened this issue 3 years ago • 11 comments

Describe the bug

Sorry, AREPL has ran into an error

Traceback (most recent call last):
  File "/usr/local/Cellar/[email protected]/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 261, in _add_reader
    key = self._selector.get_key(fd)
  File "/usr/local/Cellar/[email protected]/3.9.2_4/Frameworks/Python.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: '5 is not registered'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/jb/.vscode/extensions/almenon.arepl-2.0.2/node_modules/arepl-backend/python/arepl_python_evaluator.py", line 298, in main
    return_info = exec_input(execArgs)
  File "/Users/jb/.vscode/extensions/almenon.arepl-2.0.2/node_modules/arepl-backend/python/arepl_python_evaluator.py", line 234, in exec_input
    asyncio.set_event_loop(asyncio.new_event_loop())
  File "/usr/local/Cellar/[email protected]/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/events.py", line 761, in new_event_loop
    return get_event_loop_policy().new_event_loop()
  File "/usr/local/Cellar/[email protected]/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/events.py", line 659, in new_event_loop
    return self._loop_factory()
  File "/usr/local/Cellar/[email protected]/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/unix_events.py", line 54, in __init__
    super().__init__(selector)
  File "/usr/local/Cellar/[email protected]/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 61, in __init__
    self._make_self_pipe()
  File "/usr/local/Cellar/[email protected]/3.9.2_4/Frameworks/Python.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 "/usr/local/Cellar/[email protected]/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 263, in _add_reader
    self._selector.register(fd, selectors.EVENT_READ,
  File "/usr/local/Cellar/[email protected]/3.9.2_4/Frameworks/Python.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

Print Output:
Exception ignored in: <function BaseEventLoop.__del__ at 0x11871de50>
Traceback (most recent call last):
  File "/usr/local/Cellar/[email protected]/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 683, in __del__
    self.close()
  File "/usr/local/Cellar/[email protected]/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/unix_events.py", line 60, in close
    for sig in list(self._signal_handlers):
AttributeError: '_UnixSelectorEventLoop' object has no attribute '_signal_handlers'

To Reproduce Try typing a small program. Probably triggerable by any use of macOS and AREPL when typing a variable name that does not exist yet.

Screenshots If applicable, add screenshots to help explain your problem.

Other Information (please complete the following information):

  • OS: macOS Mojave
  • Python Version 3.9.2_4 Homebrew

jbarlow83 avatar Apr 12 '21 22:04 jbarlow83

I'm not able to reproduce on 3.9 w/ windows. Maybe it's a mac-specific bug?

Can you try running the following in the terminal using python 3.9 please and let me know the output?

from sys import version
print(version)
import asyncio
asyncio.set_event_loop(asyncio.new_event_loop())

Related error: https://github.com/eventlet/eventlet/issues/670

I wonder if this is a internal python bug 🤔

Almenon avatar Apr 14 '21 05:04 Almenon

Works fine:

In [1]: from sys import version
   ...: print(version)
   ...: import asyncio
   ...: asyncio.set_event_loop(asyncio.new_event_loop())
3.9.2 (default, Mar 26 2021, 22:33:29)
[Clang 11.0.0 (clang-1100.0.33.17)]

jbarlow83 avatar Apr 14 '21 07:04 jbarlow83

What about

from sys import version
print(version)
import asyncio
asyncio.set_event_loop(asyncio.new_event_loop())
asyncio.set_event_loop(asyncio.new_event_loop())

?

Almenon avatar Apr 14 '21 14:04 Almenon

No issue/same output.

jbarlow83 avatar Apr 14 '21 21:04 jbarlow83

I tried to reproduce this on mac el capitan and was unable too. Unfortunately I don't have a mojave-compatible computer so I'm not able to try it there.

How did you run python in the terminal? Can you prefix that command with which so I can see where the executable is please? I'm wondering if the python you're using on the terminal is the same brew python you're using in arepl.

Almenon avatar Apr 17 '21 21:04 Almenon

Oh also if you use a earlier version of python does it work with AREPL?

Almenon avatar Apr 17 '21 21:04 Almenon

What about

from sys import version
print(version)
import asyncio
asyncio.set_event_loop(asyncio.new_event_loop())
asyncio.set_event_loop(asyncio.new_event_loop())

?

I managed to get this working by changing https://github.com/Almenon/AREPL-backend/blob/master/python/arepl_python_evaluator.py#L234

from asyncio.set_event_loop(asyncio.new_event_loop())

to asyncio.set_event_loop(asyncio.get_event_loop())

My environment: MacOS 11.2.3 (Big Sur) Python 3.9.3

BrandonNav avatar Apr 29 '21 00:04 BrandonNav

Really? Very interesting... I'll look into this, thanks!

While I was investigating I also ran into another error: https://github.com/Almenon/AREPL-backend/issues/167

Looks like I have some work to do :|

Almenon avatar May 03 '21 01:05 Almenon

I've experienced the same bug whilst running a simple script using homebrew Python 3.9.5 However, running the same script on homebrew 3.8.10 works just fine.

Running your script above works fine on both 3.9.5 and 3.8.10

Mac OS 10.15.7 (Catalina) VSCode 1.57.1

Sorry, AREPL has ran into an error

Traceback (most recent call last): File "/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 261, in _add_reader key = self._selector.get_key(fd) File "/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.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: '7 is not registered'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/user1/.vscode/extensions/almenon.arepl-2.0.2/node_modules/arepl-backend/python/arepl_python_evaluator.py", line 298, in main return_info = exec_input(execArgs) File "/Users/user1/.vscode/extensions/almenon.arepl-2.0.2/node_modules/arepl-backend/python/arepl_python_evaluator.py", line 234, in exec_input asyncio.set_event_loop(asyncio.new_event_loop()) File "/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/events.py", line 761, in new_event_loop return get_event_loop_policy().new_event_loop() File "/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/events.py", line 659, in new_event_loop return self._loop_factory() File "/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/unix_events.py", line 54, in init super().init(selector) File "/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 61, in init self._make_self_pipe() File "/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.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 "/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 263, in _add_reader self._selector.register(fd, selectors.EVENT_READ, File "/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.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

Print Output: Exception ignored in: <function BaseEventLoop.del at 0x104700b80> Traceback (most recent call last): File "/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 683, in del self.close() File "/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/unix_events.py", line 60, in close for sig in list(self._signal_handlers): AttributeError: '_UnixSelectorEventLoop' object has no attribute '_signal_handlers' Variables: {}

p-clements avatar Jun 20 '21 12:06 p-clements

I'm able to reproduce this reliably using just an import statement. Reverting to Python 3.7.11 makes it work again, as does using Brandon's asyncio.set_event_loop(asyncio.get_event_loop()) fix on 3.9.6.

Environment

OS X 10.13.6 AREPL 2.0.2 VSCodium Version: 1.57.1 Commit: 507ce72a4466fbb27b715c3722558bb15afa9f48 Date: 2021-06-18T00:16:36.917Z (2 wks ago) Electron: 12.0.7 Chrome: 89.0.4389.128 Node.js: 14.16.0 V8: 8.9.255.25-electron.0 OS: Darwin x64 17.7.0

Steps to reproduce

  1. Create a python file
  2. Open the AREPL pane
  3. Type import requests
  4. Press the Enter key or spacebar
  5. Open and close the ARPL pane
  6. Add a new line: print('hello')
  7. Press the Enter key or spacebar

https://user-images.githubusercontent.com/8731045/124678808-2568d080-de78-11eb-960a-e3441b465156.mp4

If AREPL is restarted, it throws an error when new code is entered (but not when newlines are added). In my case, the KeyError usually mentions key 5, 8, or 11.

Print Output:
3.9.6 (default, Jul  4 2021, 23:21:00) 
[Clang 9.1.0 (clang-902.0.39.2)]
Exception ignored in: <function BaseEventLoop.__del__ at 0x10bd6ed30>
Traceback (most recent call last):
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 683, in __del__
    self.close()
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/unix_events.py", line 58, in close
    super().close()
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 92, in close
    self._close_self_pipe()
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 99, in _close_self_pipe
    self._remove_reader(self._ssock.fileno())
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 284, in _remove_reader
    self._selector.unregister(fd)
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/selectors.py", line 539, in unregister
    self._selector.control([kev], 0, 0)
TypeError: changelist must be an iterable of select.kevent objects
Variables:
-{
    version: +"3.9.6 (default, Jul 4 2021, 23:21:00) [Clang 9.1.0 (clang-902.0.39.2 ..."
}
57 ms

report an issue | ⭐ rate me ⭐ | talk on gitter | Tweet #arepl
Sorry, AREPL has ran into an error

Traceback (most recent call last):
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 261, in _add_reader
    key = self._selector.get_key(fd)
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.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: '11 is not registered'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/pavel/.vscode-oss/extensions/almenon.arepl-2.0.2/node_modules/arepl-backend/python/arepl_python_evaluator.py", line 298, in main
    return_info = exec_input(execArgs)
  File "/Users/pavel/.vscode-oss/extensions/almenon.arepl-2.0.2/node_modules/arepl-backend/python/arepl_python_evaluator.py", line 234, in exec_input
    asyncio.set_event_loop(asyncio.new_event_loop())
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/events.py", line 761, in new_event_loop
    return get_event_loop_policy().new_event_loop()
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/events.py", line 659, in new_event_loop
    return self._loop_factory()
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/unix_events.py", line 54, in __init__
    super().__init__(selector)
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 61, in __init__
    self._make_self_pipe()
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.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 "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 263, in _add_reader
    self._selector.register(fd, selectors.EVENT_READ,
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.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

Print Output:
Exception ignored in: <function BaseEventLoop.__del__ at 0x1025d6d30>
Traceback (most recent call last):
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 683, in __del__
    self.close()
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/unix_events.py", line 60, in close
    for sig in list(self._signal_handlers):
AttributeError: '_UnixSelectorEventLoop' object has no attribute '_signal_handlers'
Variables:
{}
0 ms

report an issue | ⭐ rate me ⭐ | talk on gitter | Tweet #arepl

pkirkovsky avatar Jul 06 '21 23:07 pkirkovsky

Finally got access to a Mac. I can reproduce the bug on 3.9, but the bug does not occur on 3.10. I suggest either using the fix workaround above, downgrading to 3.7, or upgrading to 3.10.

The other interesting thing is that for me this only occurs in the third arepl run.

Almenon avatar May 31 '22 00:05 Almenon