##// 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 16 from IPython.nbformat.current import reads, NotebookNode, writes
17 17 from .base import Preprocessor
18
19 # default timeout for reply and output: 10s
20 TIMEOUT = 10
18 from IPython.utils.traitlets import Integer
21 19
22 20 class ExecutePreprocessor(Preprocessor):
23 21 """
24 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 28 # FIXME: to be removed with nbformat v4
28 29 # map msg_type to v3 output_type
29 30 msg_type_map = {
@@ -49,22 +50,24 b' class ExecutePreprocessor(Preprocessor):'
49 50 def _create_client(self):
50 51 from IPython.kernel import KernelManager
51 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 54 self.kc = self.km.client()
54 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 57 self.iopub = self.kc.iopub_channel
57 58 self.shell = self.kc.shell_channel
58 59 self.shell.kernel_info()
59 60 try:
60 self.shell.get_msg(timeout=TIMEOUT)
61 self.shell.get_msg(timeout=self.timeout)
61 62 except Empty:
62 63 self.log.error("Timeout waiting for kernel_info reply")
63 64 raise
64 try:
65 self.iopub.get_msg(timeout=TIMEOUT)
66 except Empty:
67 self.log.warn("Timeout waiting for IOPub on startup")
65 # flush IOPub
66 while True:
67 try:
68 self.iopub.get_msg(block=True, timeout=0.25)
69 except Empty:
70 break
68 71
69 72 def _shutdown_client(self):
70 73 self.kc.stop_channels()
@@ -98,7 +101,7 b' class ExecutePreprocessor(Preprocessor):'
98 101 # wait for finish, with timeout
99 102 while True:
100 103 try:
101 msg = shell.get_msg(timeout=TIMEOUT)
104 msg = shell.get_msg(timeout=self.timeout)
102 105 except Empty:
103 106 self.log.error("Timeout waiting for execute reply")
104 107 raise
@@ -112,7 +115,7 b' class ExecutePreprocessor(Preprocessor):'
112 115
113 116 while True:
114 117 try:
115 msg = iopub.get_msg(timeout=TIMEOUT)
118 msg = iopub.get_msg(timeout=self.timeout)
116 119 except Empty:
117 120 self.log.warn("Timeout waiting for IOPub output")
118 121 break
General Comments 0
You need to be logged in to leave comments. Login now