-
-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #281 from minrk/asyncio-fix
handle KeyboardInterrupt with %gui asyncio
- Loading branch information
Showing
4 changed files
with
86 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""test utilities that use async/await syntax | ||
a separate file to avoid syntax errors on Python 2 | ||
""" | ||
|
||
import asyncio | ||
|
||
|
||
def async_func(): | ||
"""Simple async function to schedule a task on the current eventloop""" | ||
loop = asyncio.get_event_loop() | ||
assert loop.is_running() | ||
|
||
async def task(): | ||
await asyncio.sleep(1) | ||
|
||
loop.create_task(task()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Test eventloop integration""" | ||
|
||
import sys | ||
import time | ||
|
||
import IPython.testing.decorators as dec | ||
from .utils import flush_channels, start_new_kernel, execute | ||
|
||
KC = KM = None | ||
|
||
|
||
def setup(): | ||
"""start the global kernel (if it isn't running) and return its client""" | ||
global KM, KC | ||
KM, KC = start_new_kernel() | ||
flush_channels(KC) | ||
|
||
|
||
def teardown(): | ||
KC.stop_channels() | ||
KM.shutdown_kernel(now=True) | ||
|
||
|
||
async_code = """ | ||
from ipykernel.tests._asyncio import async_func | ||
async_func() | ||
""" | ||
|
||
|
||
@dec.skipif(sys.version_info < (3, 5), "async/await syntax required") | ||
def test_asyncio_interrupt(): | ||
flush_channels(KC) | ||
msg_id, content = execute('%gui asyncio', KC) | ||
assert content['status'] == 'ok', content | ||
|
||
flush_channels(KC) | ||
msg_id, content = execute(async_code, KC) | ||
assert content['status'] == 'ok', content | ||
|
||
KM.interrupt_kernel() | ||
|
||
flush_channels(KC) | ||
msg_id, content = execute(async_code, KC) | ||
assert content['status'] == 'ok' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters