|
1 | 1 | """Test Parallel magics"""
|
2 | 2 | import re
|
| 3 | +import signal |
3 | 4 | import sys
|
4 | 5 | import time
|
5 | 6 |
|
@@ -480,3 +481,45 @@ def test_cellpx_block(self):
|
480 | 481 | pass
|
481 | 482 | self.assertNotIn('Async', io.stdout)
|
482 | 483 | self.assertEqual(view.block, False)
|
| 484 | + |
| 485 | + def cellpx_keyboard_interrupt_test_helper(self, sig=None): |
| 486 | + """%%px with Keyboard Interrupt on blocking execution""" |
| 487 | + |
| 488 | + ip = get_ipython() |
| 489 | + v = self.client[:] |
| 490 | + v.block = True |
| 491 | + v.activate() |
| 492 | + |
| 493 | + def _sigalarm(sig, frame): |
| 494 | + raise KeyboardInterrupt |
| 495 | + |
| 496 | + signal.signal(signal.SIGALRM, _sigalarm) |
| 497 | + signal.alarm(2) |
| 498 | + with capture_output(display=False) as io: |
| 499 | + ip.run_cell_magic( |
| 500 | + "px", |
| 501 | + "" if sig is None else f"--signal-on-interrupt {sig}", |
| 502 | + "print('Entering...'); import time; time.sleep(5); print('Exiting...');", |
| 503 | + ) |
| 504 | + |
| 505 | + print(io.stdout) |
| 506 | + print(io.stderr, file=sys.stderr) |
| 507 | + assert ( |
| 508 | + 'Received Keyboard Interrupt. Sending signal {} to engines...'.format( |
| 509 | + "SIGINT" if sig is None else sig |
| 510 | + ) |
| 511 | + in io.stderr |
| 512 | + ) |
| 513 | + assert 'Exiting...' not in io.stdout |
| 514 | + |
| 515 | + def test_cellpx_keyboard_interrupt_default(self): |
| 516 | + self.cellpx_keyboard_interrupt_test_helper() |
| 517 | + |
| 518 | + def test_cellpx_keyboard_interrupt_SIGINT(self): |
| 519 | + self.cellpx_keyboard_interrupt_test_helper("SIGINT") |
| 520 | + |
| 521 | + def test_cellpx_keyboard_interrupt_signal_2(self): |
| 522 | + self.cellpx_keyboard_interrupt_test_helper("2") |
| 523 | + |
| 524 | + def test_cellpx_keyboard_interrupt_signal_0(self): |
| 525 | + self.cellpx_keyboard_interrupt_test_helper("0") |
0 commit comments