File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 55# Distributed under the terms of the Modified BSD License.
66
77from __future__ import print_function
8+ import atexit
89import os
910import threading
1011import sys
@@ -116,9 +117,14 @@ def _check_mp_mode(self):
116117 def start (self ):
117118 """Start the IOPub thread"""
118119 self .thread .start ()
120+ # make sure we don't prevent process exit
121+ # I'm not sure why setting daemon=True above isn't enough, but it doesn't appear to be.
122+ atexit .register (self .stop )
119123
120124 def stop (self ):
121125 """Stop the IOPub thread"""
126+ if not self .thread .is_alive ():
127+ return
122128 self .io_loop .add_callback (self .io_loop .stop )
123129 self .thread .join ()
124130
Original file line number Diff line number Diff line change 77import io
88import os .path
99import sys
10+ import time
1011
1112import nose .tools as nt
1213
@@ -242,3 +243,19 @@ def test_complete():
242243 nt .assert_greater (len (matches ), 0 )
243244 for match in matches :
244245 nt .assert_equal (match [:2 ], 'a.' )
246+
247+
248+ def test_shutdown ():
249+ """Kernel exits after polite shutdown_request"""
250+ with new_kernel () as kc :
251+ km = kc .parent
252+ execute (u'a = 1' , kc = kc )
253+ wait_for_idle (kc )
254+ kc .shutdown ()
255+ for i in range (100 ): # 10s timeout
256+ if km .is_alive ():
257+ time .sleep (.1 )
258+ else :
259+ break
260+ nt .assert_false (km .is_alive ())
261+
You can’t perform that action at this time.
0 commit comments