##// END OF EJS Templates
make execute preprocessor timeout configurable
MinRK -
Show More
@@ -15,15 +15,16 b' from IPython.utils.traitlets import List, Unicode'
15
15
16 from IPython.nbformat.current import reads, NotebookNode, writes
16 from IPython.nbformat.current import reads, NotebookNode, writes
17 from .base import Preprocessor
17 from .base import Preprocessor
18
18 from IPython.utils.traitlets import Integer
19 # default timeout for reply and output: 10s
20 TIMEOUT = 10
21
19
22 class ExecutePreprocessor(Preprocessor):
20 class ExecutePreprocessor(Preprocessor):
23 """
21 """
24 Executes all the cells in a notebook
22 Executes all the cells in a notebook
25 """
23 """
26
24
25 timeout = Integer(30, config=True,
26 help="The time to wait (in seconds) for output from executions."
27 )
27 # FIXME: to be removed with nbformat v4
28 # FIXME: to be removed with nbformat v4
28 # map msg_type to v3 output_type
29 # map msg_type to v3 output_type
29 msg_type_map = {
30 msg_type_map = {
@@ -49,22 +50,24 b' class ExecutePreprocessor(Preprocessor):'
49 def _create_client(self):
50 def _create_client(self):
50 from IPython.kernel import KernelManager
51 from IPython.kernel import KernelManager
51 self.km = KernelManager()
52 self.km = KernelManager()
52 self.km.start_kernel(extra_arguments=self.extra_arguments, stderr=open(os.devnull, 'w'))
53 self.km.write_connection_file()
53 self.kc = self.km.client()
54 self.kc = self.km.client()
54 self.kc.start_channels()
55 self.kc.start_channels()
55 self.log.debug('kc.start_channels: %s', self.kc.session.session)
56 self.km.start_kernel(extra_arguments=self.extra_arguments, stderr=open(os.devnull, 'w'))
56 self.iopub = self.kc.iopub_channel
57 self.iopub = self.kc.iopub_channel
57 self.shell = self.kc.shell_channel
58 self.shell = self.kc.shell_channel
58 self.shell.kernel_info()
59 self.shell.kernel_info()
59 try:
60 try:
60 self.shell.get_msg(timeout=TIMEOUT)
61 self.shell.get_msg(timeout=self.timeout)
61 except Empty:
62 except Empty:
62 self.log.error("Timeout waiting for kernel_info reply")
63 self.log.error("Timeout waiting for kernel_info reply")
63 raise
64 raise
64 try:
65 # flush IOPub
65 self.iopub.get_msg(timeout=TIMEOUT)
66 while True:
66 except Empty:
67 try:
67 self.log.warn("Timeout waiting for IOPub on startup")
68 self.iopub.get_msg(block=True, timeout=0.25)
69 except Empty:
70 break
68
71
69 def _shutdown_client(self):
72 def _shutdown_client(self):
70 self.kc.stop_channels()
73 self.kc.stop_channels()
@@ -98,7 +101,7 b' class ExecutePreprocessor(Preprocessor):'
98 # wait for finish, with timeout
101 # wait for finish, with timeout
99 while True:
102 while True:
100 try:
103 try:
101 msg = shell.get_msg(timeout=TIMEOUT)
104 msg = shell.get_msg(timeout=self.timeout)
102 except Empty:
105 except Empty:
103 self.log.error("Timeout waiting for execute reply")
106 self.log.error("Timeout waiting for execute reply")
104 raise
107 raise
@@ -112,7 +115,7 b' class ExecutePreprocessor(Preprocessor):'
112
115
113 while True:
116 while True:
114 try:
117 try:
115 msg = iopub.get_msg(timeout=TIMEOUT)
118 msg = iopub.get_msg(timeout=self.timeout)
116 except Empty:
119 except Empty:
117 self.log.warn("Timeout waiting for IOPub output")
120 self.log.warn("Timeout waiting for IOPub output")
118 break
121 break
General Comments 0
You need to be logged in to leave comments. Login now