We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Making stdin optional when creating new kernels
It would be useful for the `ExecutePreprocessor` (and other things that want to automatically run notebooks on the fly) to be able to easily disable `stdin` -- otherwise, if there is something like a call to `input`, it causes the preprocessor to just hang and eventually time out. I think this would just involve adding a new kwarg to this function: https://github.com/ipython/ipython/blob/master/IPython/kernel/manager.py#L417 and then calling `kc.start_channels(stdin=stdin)`, where `stdin` is whatever value that was passed in (True by default).

Questions:
1. Is there some other way to do this that I missed?
2. If not, does this change sound ok? If so, I'll go ahead and make a PR for it and add an option to disable stdin to the `ExecutePreprocessor` as well.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `IPython/nbconvert/preprocessors/execute.py`
Content:
```
1 """Module containing a preprocessor that removes the outputs from code cells"""
2 
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
5 
6 import os
7 
8 try:
9     from queue import Empty  # Py 3
10 except ImportError:
11     from Queue import Empty  # Py 2
12 
13 from IPython.utils.traitlets import List, Unicode
14 
15 from IPython.nbformat.v4 import output_from_msg
16 from .base import Preprocessor
17 from IPython.utils.traitlets import Integer
18 
19 
20 class ExecutePreprocessor(Preprocessor):
21     """
22     Executes all the cells in a notebook
23     """
24     
25     timeout = Integer(30, config=True,
26         help="The time to wait (in seconds) for output from executions."
27     )
28     
29     extra_arguments = List(Unicode)
30 
31     def preprocess(self, nb, resources):
32         from IPython.kernel import run_kernel
33         kernel_name = nb.metadata.get('kernelspec', {}).get('name', 'python')
34         self.log.info("Executing notebook with kernel: %s" % kernel_name)
35         with run_kernel(kernel_name=kernel_name,
36                         extra_arguments=self.extra_arguments,
37                         stderr=open(os.devnull, 'w')) as kc:
38             self.kc = kc
39             nb, resources = super(ExecutePreprocessor, self).preprocess(nb, resources)
40         return nb, resources
41 
42     def preprocess_cell(self, cell, resources, cell_index):
43         """
44         Apply a transformation on each code cell. See base.py for details.
45         """
46         if cell.cell_type != 'code':
47             return cell, resources
48         try:
49             outputs = self.run_cell(cell)
50         except Exception as e:
51             self.log.error("failed to run cell: " + repr(e))
52             self.log.error(str(cell.source))
53             raise
54         cell.outputs = outputs
55         return cell, resources
56 
57     def run_cell(self, cell):
58         msg_id = self.kc.execute(cell.source)
59         self.log.debug("Executing cell:\n%s", cell.source)
60         # wait for finish, with timeout
61         while True:
62             try:
63                 msg = self.kc.shell_channel.get_msg(timeout=self.timeout)
64             except Empty:
65                 self.log.error("Timeout waiting for execute reply")
66                 raise
67             if msg['parent_header'].get('msg_id') == msg_id:
68                 break
69             else:
70                 # not our reply
71                 continue
72         
73         outs = []
74 
75         while True:
76             try:
77                 msg = self.kc.iopub_channel.get_msg(timeout=self.timeout)
78             except Empty:
79                 self.log.warn("Timeout waiting for IOPub output")
80                 break
81             if msg['parent_header'].get('msg_id') != msg_id:
82                 # not an output from our execution
83                 continue
84 
85             msg_type = msg['msg_type']
86             self.log.debug("output: %s", msg_type)
87             content = msg['content']
88 
89             # set the prompt number for the input and the output
90             if 'execution_count' in content:
91                 cell['execution_count'] = content['execution_count']
92 
93             if msg_type == 'status':
94                 if content['execution_state'] == 'idle':
95                     break
96                 else:
97                     continue
98             elif msg_type == 'execute_input':
99                 continue
100             elif msg_type == 'clear_output':
101                 outs = []
102                 continue
103 
104             try:
105                 out = output_from_msg(msg)
106             except ValueError:
107                 self.log.error("unhandled iopub msg: " + msg_type)
108             else:
109                 outs.append(out)
110 
111         return outs
112
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/IPython/nbconvert/preprocessors/execute.py b/IPython/nbconvert/preprocessors/execute.py
--- a/IPython/nbconvert/preprocessors/execute.py
+++ b/IPython/nbconvert/preprocessors/execute.py
@@ -36,6 +36,7 @@
                         extra_arguments=self.extra_arguments,
                         stderr=open(os.devnull, 'w')) as kc:
             self.kc = kc
+            self.kc.allow_stdin = False
             nb, resources = super(ExecutePreprocessor, self).preprocess(nb, resources)
         return nb, resources

{"golden_diff": "diff --git a/IPython/nbconvert/preprocessors/execute.py b/IPython/nbconvert/preprocessors/execute.py\n--- a/IPython/nbconvert/preprocessors/execute.py\n+++ b/IPython/nbconvert/preprocessors/execute.py\n@@ -36,6 +36,7 @@\n                         extra_arguments=self.extra_arguments,\n                         stderr=open(os.devnull, 'w')) as kc:\n             self.kc = kc\n+            self.kc.allow_stdin = False\n             nb, resources = super(ExecutePreprocessor, self).preprocess(nb, resources)\n         return nb, resources\n", "issue": "Making stdin optional when creating new kernels\nIt would be useful for the `ExecutePreprocessor` (and other things that want to automatically run notebooks on the fly) to be able to easily disable `stdin` -- otherwise, if there is something like a call to `input`, it causes the preprocessor to just hang and eventually time out. I think this would just involve adding a new kwarg to this function: https://github.com/ipython/ipython/blob/master/IPython/kernel/manager.py#L417 and then calling `kc.start_channels(stdin=stdin)`, where `stdin` is whatever value that was passed in (True by default).\n\nQuestions:\n1. Is there some other way to do this that I missed?\n2. If not, does this change sound ok? If so, I'll go ahead and make a PR for it and add an option to disable stdin to the `ExecutePreprocessor` as well.\n\n", "before_files": [{"content": "\"\"\"Module containing a preprocessor that removes the outputs from code cells\"\"\"\n\n# Copyright (c) IPython Development Team.\n# Distributed under the terms of the Modified BSD License.\n\nimport os\n\ntry:\n    from queue import Empty  # Py 3\nexcept ImportError:\n    from Queue import Empty  # Py 2\n\nfrom IPython.utils.traitlets import List, Unicode\n\nfrom IPython.nbformat.v4 import output_from_msg\nfrom .base import Preprocessor\nfrom IPython.utils.traitlets import Integer\n\n\nclass ExecutePreprocessor(Preprocessor):\n    \"\"\"\n    Executes all the cells in a notebook\n    \"\"\"\n    \n    timeout = Integer(30, config=True,\n        help=\"The time to wait (in seconds) for output from executions.\"\n    )\n    \n    extra_arguments = List(Unicode)\n\n    def preprocess(self, nb, resources):\n        from IPython.kernel import run_kernel\n        kernel_name = nb.metadata.get('kernelspec', {}).get('name', 'python')\n        self.log.info(\"Executing notebook with kernel: %s\" % kernel_name)\n        with run_kernel(kernel_name=kernel_name,\n                        extra_arguments=self.extra_arguments,\n                        stderr=open(os.devnull, 'w')) as kc:\n            self.kc = kc\n            nb, resources = super(ExecutePreprocessor, self).preprocess(nb, resources)\n        return nb, resources\n\n    def preprocess_cell(self, cell, resources, cell_index):\n        \"\"\"\n        Apply a transformation on each code cell. See base.py for details.\n        \"\"\"\n        if cell.cell_type != 'code':\n            return cell, resources\n        try:\n            outputs = self.run_cell(cell)\n        except Exception as e:\n            self.log.error(\"failed to run cell: \" + repr(e))\n            self.log.error(str(cell.source))\n            raise\n        cell.outputs = outputs\n        return cell, resources\n\n    def run_cell(self, cell):\n        msg_id = self.kc.execute(cell.source)\n        self.log.debug(\"Executing cell:\\n%s\", cell.source)\n        # wait for finish, with timeout\n        while True:\n            try:\n                msg = self.kc.shell_channel.get_msg(timeout=self.timeout)\n            except Empty:\n                self.log.error(\"Timeout waiting for execute reply\")\n                raise\n            if msg['parent_header'].get('msg_id') == msg_id:\n                break\n            else:\n                # not our reply\n                continue\n        \n        outs = []\n\n        while True:\n            try:\n                msg = self.kc.iopub_channel.get_msg(timeout=self.timeout)\n            except Empty:\n                self.log.warn(\"Timeout waiting for IOPub output\")\n                break\n            if msg['parent_header'].get('msg_id') != msg_id:\n                # not an output from our execution\n                continue\n\n            msg_type = msg['msg_type']\n            self.log.debug(\"output: %s\", msg_type)\n            content = msg['content']\n\n            # set the prompt number for the input and the output\n            if 'execution_count' in content:\n                cell['execution_count'] = content['execution_count']\n\n            if msg_type == 'status':\n                if content['execution_state'] == 'idle':\n                    break\n                else:\n                    continue\n            elif msg_type == 'execute_input':\n                continue\n            elif msg_type == 'clear_output':\n                outs = []\n                continue\n\n            try:\n                out = output_from_msg(msg)\n            except ValueError:\n                self.log.error(\"unhandled iopub msg: \" + msg_type)\n            else:\n                outs.append(out)\n\n        return outs\n", "path": "IPython/nbconvert/preprocessors/execute.py"}], "after_files": [{"content": "\"\"\"Module containing a preprocessor that removes the outputs from code cells\"\"\"\n\n# Copyright (c) IPython Development Team.\n# Distributed under the terms of the Modified BSD License.\n\nimport os\n\ntry:\n    from queue import Empty  # Py 3\nexcept ImportError:\n    from Queue import Empty  # Py 2\n\nfrom IPython.utils.traitlets import List, Unicode\n\nfrom IPython.nbformat.v4 import output_from_msg\nfrom .base import Preprocessor\nfrom IPython.utils.traitlets import Integer\n\n\nclass ExecutePreprocessor(Preprocessor):\n    \"\"\"\n    Executes all the cells in a notebook\n    \"\"\"\n    \n    timeout = Integer(30, config=True,\n        help=\"The time to wait (in seconds) for output from executions.\"\n    )\n    \n    extra_arguments = List(Unicode)\n\n    def preprocess(self, nb, resources):\n        from IPython.kernel import run_kernel\n        kernel_name = nb.metadata.get('kernelspec', {}).get('name', 'python')\n        self.log.info(\"Executing notebook with kernel: %s\" % kernel_name)\n        with run_kernel(kernel_name=kernel_name,\n                        extra_arguments=self.extra_arguments,\n                        stderr=open(os.devnull, 'w')) as kc:\n            self.kc = kc\n            self.kc.allow_stdin = False\n            nb, resources = super(ExecutePreprocessor, self).preprocess(nb, resources)\n        return nb, resources\n\n    def preprocess_cell(self, cell, resources, cell_index):\n        \"\"\"\n        Apply a transformation on each code cell. See base.py for details.\n        \"\"\"\n        if cell.cell_type != 'code':\n            return cell, resources\n        try:\n            outputs = self.run_cell(cell)\n        except Exception as e:\n            self.log.error(\"failed to run cell: \" + repr(e))\n            self.log.error(str(cell.source))\n            raise\n        cell.outputs = outputs\n        return cell, resources\n\n    def run_cell(self, cell):\n        msg_id = self.kc.execute(cell.source)\n        self.log.debug(\"Executing cell:\\n%s\", cell.source)\n        # wait for finish, with timeout\n        while True:\n            try:\n                msg = self.kc.shell_channel.get_msg(timeout=self.timeout)\n            except Empty:\n                self.log.error(\"Timeout waiting for execute reply\")\n                raise\n            if msg['parent_header'].get('msg_id') == msg_id:\n                break\n            else:\n                # not our reply\n                continue\n        \n        outs = []\n\n        while True:\n            try:\n                msg = self.kc.iopub_channel.get_msg(timeout=self.timeout)\n            except Empty:\n                self.log.warn(\"Timeout waiting for IOPub output\")\n                break\n            if msg['parent_header'].get('msg_id') != msg_id:\n                # not an output from our execution\n                continue\n\n            msg_type = msg['msg_type']\n            self.log.debug(\"output: %s\", msg_type)\n            content = msg['content']\n\n            # set the prompt number for the input and the output\n            if 'execution_count' in content:\n                cell['execution_count'] = content['execution_count']\n\n            if msg_type == 'status':\n                if content['execution_state'] == 'idle':\n                    break\n                else:\n                    continue\n            elif msg_type == 'execute_input':\n                continue\n            elif msg_type == 'clear_output':\n                outs = []\n                continue\n\n            try:\n                out = output_from_msg(msg)\n            except ValueError:\n                self.log.error(\"unhandled iopub msg: \" + msg_type)\n            else:\n                outs.append(out)\n\n        return outs\n", "path": "IPython/nbconvert/preprocessors/execute.py"}]}