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

PR: Fix conflict between AsyncDispatcher and run_sync function of jupyter_core #22137

Merged

Conversation

hlouzada
Copy link
Contributor

Description of Changes

  • Wrote at least one-line docstrings (for any new functions)
  • Added unit test(s) covering the changes (if testable)

Allow AsyncDispatcher to get the "main thread" running loop without depending on asyncio.set_event_loop and asyncio.get_running_loop so it won't trigger conflict with how jupyter_core.utils.run_sync handles creating, setting and executing event loops.

Also, refactor type hints to help with hinting decoreted async functions.

Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

I certify the above statement is true and correct:

@hlouzada

@pep8speaks
Copy link

pep8speaks commented May 30, 2024

Hello @hlouzada! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2024-06-09 23:28:07 UTC

@hlouzada hlouzada force-pushed the fix-remote-client-new-kernel-bug branch from 61c0ab9 to ee4a2c5 Compare May 30, 2024 17:12
Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

Thanks @hlouzada for your work on this! I only left some formatting suggestions for you.

spyder/api/asyncdispatcher.py Show resolved Hide resolved
spyder/api/asyncdispatcher.py Show resolved Hide resolved
spyder/api/asyncdispatcher.py Show resolved Hide resolved
spyder/api/asyncdispatcher.py Show resolved Hide resolved
spyder/api/asyncdispatcher.py Show resolved Hide resolved
spyder/api/asyncdispatcher.py Show resolved Hide resolved
spyder/api/asyncdispatcher.py Show resolved Hide resolved
@ccordoba12 ccordoba12 added this to the v6.0beta2 milestone May 31, 2024
@ccordoba12 ccordoba12 changed the title PR: Fix issue with asyncdispaycher conflict with jupyter_core run_sync PR: Fix conflict between AsyncDispatcher and run_sync function of jupyter_core May 31, 2024
@ccordoba12 ccordoba12 requested a review from dalthviz May 31, 2024 01:31
@ccordoba12
Copy link
Member

@dalthviz, could you check that you can start remote consoles on Windows with this PR? Thanks!

@hlouzada discovered that these fixes are necessary mainly there (although they'll be useful for Linux and Mac too).

@dalthviz
Copy link
Member

dalthviz commented Jun 4, 2024

Gave this a check on Windows and got some different behaviors. In an old dev env I have I'm got a RuntimeError:

Traceback (most recent call last):
  File "e:\acer\documentos\spyder\spyder otros\hlouzada\spyder\external-deps\qtconsole\qtconsole\manager.py", line 27, in poll
    super().poll()
  File "C:\Users\dalth\anaconda3\envs\spyder-dev\lib\site-packages\jupyter_client\restarter.py", line 121, in poll
    if not self.kernel_manager.is_alive():
  File "C:\Users\dalth\anaconda3\envs\spyder-dev\lib\site-packages\jupyter_core\utils\__init__.py", line 173, in wrapped
    return loop.run_until_complete(inner)
  File "C:\Users\dalth\anaconda3\envs\spyder-dev\lib\asyncio\base_events.py", line 625, in run_until_complete
    self._check_running()
  File "C:\Users\dalth\anaconda3\envs\spyder-dev\lib\asyncio\base_events.py", line 584, in _check_running
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
Traceback (most recent call last):
  File "e:\acer\documentos\spyder\spyder otros\hlouzada\spyder\external-deps\qtconsole\qtconsole\manager.py", line 27, in poll
    super().poll()
  File "C:\Users\dalth\anaconda3\envs\spyder-dev\lib\site-packages\jupyter_client\restarter.py", line 121, in poll
    if not self.kernel_manager.is_alive():
  File "C:\Users\dalth\anaconda3\envs\spyder-dev\lib\site-packages\jupyter_core\utils\__init__.py", line 173, in wrapped
    return loop.run_until_complete(inner)
  File "C:\Users\dalth\anaconda3\envs\spyder-dev\lib\asyncio\base_events.py", line 625, in run_until_complete
    self._check_running()
  File "C:\Users\dalth\anaconda3\envs\spyder-dev\lib\asyncio\base_events.py", line 584, in _check_running
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running

However, in a newer env I got just the connection dialog showing that the connection errored (when using the container private ip):

image

Checking the container files did a test using localhost/127.0.0.1 and the mapped port and I got a connection to be stablished but then all you see is the console restarting continuously:

image

and for some reason from the cmd that I used to lauch Spyder seems like the script to install spyder on dev mode starts to run?:

image

Also, after closing Spyder, I still got some output:

image

so I had to interrupt things (Ctrl + C):

image

@hlouzada
Copy link
Contributor Author

hlouzada commented Jun 4, 2024

Gave this a check on Windows and got some different behaviors. In an old dev env I have I'm got a RuntimeError:

Traceback (most recent call last):
  File "e:\acer\documentos\spyder\spyder otros\hlouzada\spyder\external-deps\qtconsole\qtconsole\manager.py", line 27, in poll
    super().poll()
  File "C:\Users\dalth\anaconda3\envs\spyder-dev\lib\site-packages\jupyter_client\restarter.py", line 121, in poll
    if not self.kernel_manager.is_alive():
  File "C:\Users\dalth\anaconda3\envs\spyder-dev\lib\site-packages\jupyter_core\utils\__init__.py", line 173, in wrapped
    return loop.run_until_complete(inner)
  File "C:\Users\dalth\anaconda3\envs\spyder-dev\lib\asyncio\base_events.py", line 625, in run_until_complete
    self._check_running()
  File "C:\Users\dalth\anaconda3\envs\spyder-dev\lib\asyncio\base_events.py", line 584, in _check_running
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
Traceback (most recent call last):
  File "e:\acer\documentos\spyder\spyder otros\hlouzada\spyder\external-deps\qtconsole\qtconsole\manager.py", line 27, in poll
    super().poll()
  File "C:\Users\dalth\anaconda3\envs\spyder-dev\lib\site-packages\jupyter_client\restarter.py", line 121, in poll
    if not self.kernel_manager.is_alive():
  File "C:\Users\dalth\anaconda3\envs\spyder-dev\lib\site-packages\jupyter_core\utils\__init__.py", line 173, in wrapped
    return loop.run_until_complete(inner)
  File "C:\Users\dalth\anaconda3\envs\spyder-dev\lib\asyncio\base_events.py", line 625, in run_until_complete
    self._check_running()
  File "C:\Users\dalth\anaconda3\envs\spyder-dev\lib\asyncio\base_events.py", line 584, in _check_running
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running

However, in a newer env I got just the connection dialog showing that the connection errored (when using the container private ip):

image

Checking the container files did a test using localhost/127.0.0.1 and the mapped port and I got a connection to be stablished but then all you see is the console restarting continuously:

image

and for some reason from the cmd that I used to lauch Spyder seems like the script to install spyder on dev mode starts to run?:

image

Also, after closing Spyder, I still got some output:

image

so I had to interrupt things (Ctrl + C):

image

Thanks for the info @dalthviz, I'll take a look and get back to you.

@dalthviz
Copy link
Member

dalthviz commented Jun 4, 2024

Just in case, did a check on a Linux VM and I got the same restarting kernel behavior when conneting:

image

Maybe I'm missing setting up something? 🤔

@hlouzada hlouzada force-pushed the fix-remote-client-new-kernel-bug branch from 8996593 to b14fd0a Compare June 9, 2024 19:51
@ccordoba12
Copy link
Member

ccordoba12 commented Jun 17, 2024

Maybe I'm missing setting up something? 🤔

After some digging, @hlouzada and @dalthviz think this could be due to a networking problem in @dalthviz's system. However, we'll continue to investigate that and try to find the issue before 6.0 final is released.

Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

Thanks @hlouzada!

@ccordoba12 ccordoba12 merged commit fcecb97 into spyder-ide:master Jun 17, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants