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

Use loop.create_task with interact() #270

Merged
merged 4 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
Expand Down
38 changes: 19 additions & 19 deletions jupyter_console/ptshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,31 +649,31 @@ async def interact(self, loop=None, display_banner=None):
if code:
self.run_cell(code, store_history=True)

async def _main_task(self):
loop = asyncio.get_running_loop()
tasks = [asyncio.create_task(self.interact(loop=loop))]

if self.include_other_output:
# only poll the iopub channel asynchronously if we
# wish to include external content
tasks.append(asyncio.create_task(self.handle_external_iopub(loop=loop)))

_, pending = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)

for task in pending:
task.cancel()
try:
await asyncio.gather(*pending)
except asyncio.CancelledError:
pass

def mainloop(self):
self.keepkernel = not self.own_kernel
loop = asyncio.get_event_loop()
# An extra layer of protection in case someone mashing Ctrl-C breaks
# out of our internal code.
while True:
try:
tasks = [self.interact(loop=loop)]

if self.include_other_output:
# only poll the iopub channel asynchronously if we
# wish to include external content
tasks.append(self.handle_external_iopub(loop=loop))

main_task = asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
_, pending = loop.run_until_complete(main_task)

for task in pending:
task.cancel()
try:
loop.run_until_complete(asyncio.gather(*pending))
except asyncio.CancelledError:
pass
loop.stop()
loop.close()
asyncio.run(self._main_task())
break
except KeyboardInterrupt:
print("\nKeyboardInterrupt escaped interact()\n")
Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[mypy]
python_version = 3.6
python_version = 3.7
ignore_missing_imports = True
follow_imports = silent
43 changes: 1 addition & 42 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,6 @@
# the name of the project
name = 'jupyter_console'

#-----------------------------------------------------------------------------
# Minimal Python version sanity check
#-----------------------------------------------------------------------------

import sys


if sys.version_info < (3, 6):
pip_message = 'This may be due to an out of date pip. Make sure you have pip >= 9.0.1.'
try:
import pip
pip_version = tuple([int(x) for x in pip.__version__.split('.')[:3]])
if pip_version < (9, 0, 1) :
pip_message = 'Your pip version is out of date, please install pip >= 9.0.1. '\
'pip {} detected.'.format(pip.__version__)
else:
# pip is new enough - it must be something else
pip_message = ''
except Exception:
pass


error = """
Jupyter_Console 6.2+ supports Python 3.6 and above.
When using Python 2.7, please install and older version of Jupyter Console
Python 3.3 and 3.4 were supported up to Jupyter Console 5.x.
Python 3.5 was supported up to Jupyter Console 6.1.0.

Python {py} detected.
{pip}
""".format(py=sys.version_info, pip=pip_message )

print(error, file=sys.stderr)
sys.exit(1)


#-----------------------------------------------------------------------------
# get on with it
#-----------------------------------------------------------------------------

import os

from setuptools import setup
Expand Down Expand Up @@ -82,7 +42,6 @@
'License :: OSI Approved :: BSD License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
Expand All @@ -97,7 +56,7 @@
extras_require={
'test:sys_platform != "win32"': ['pexpect'],
},
python_requires='>=3.6',
python_requires='>=3.7',
entry_points={
'console_scripts': [
'jupyter-console = jupyter_console.app:main',
Expand Down