We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
SciPy.weave broken in IPython notebook/ qtconsole 
# Problem

Compiling and running of compiled scipy.weave code is not possible with IPython notebook and IPython console. However, it works with standalone, plain IPython.
# Minimal Example

http://projects.scipy.org/scipy/browser/trunk/Lib/weave/examples/array3d.py?rev=1558
# Error
## compiling code

find the traceback here:
http://pastebin.com/FdSadJtV
final error:
AttributeError: 'OutStream' object has no attribute 'fileno'
## executing code

For both notebook and qtconsole, the output is printed in the terminal that was used to start them.
# tested version
## failure in

ipython 0.13.1
scipy  '0.11.0' 
numpy '1.7.0'
## working in
### compilation

Apparently it is working with numpy 1.6.0. I did not test it by myself, but that was a response on IRC. It was there also reproduced using numpy 1.7.0. I could compile it in an virtualenv using numpy 1.6 using the notebook. (Still trying to get the qtconsole to run so that I can test that)
### output

Even with numpy 1.6 the output is directed to the terminal that was used to start the IPython kernel


--- 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/kernel/zmq/iostream.py`
Content:
```
1 """wrappers for stdout/stderr forwarding over zmq
2 """
3 
4 #-----------------------------------------------------------------------------
5 #  Copyright (C) 2013  The IPython Development Team
6 #
7 #  Distributed under the terms of the BSD License.  The full license is in
8 #  the file COPYING, distributed as part of this software.
9 #-----------------------------------------------------------------------------
10 
11 import sys
12 import time
13 import os
14 import threading
15 import uuid
16 from io import StringIO
17 
18 import zmq
19 
20 from session import extract_header
21 
22 from IPython.utils import py3compat
23 
24 #-----------------------------------------------------------------------------
25 # Globals
26 #-----------------------------------------------------------------------------
27 
28 MASTER = 0
29 CHILD = 1
30 
31 #-----------------------------------------------------------------------------
32 # Stream classes
33 #-----------------------------------------------------------------------------
34 
35 class OutStream(object):
36     """A file like object that publishes the stream to a 0MQ PUB socket."""
37 
38     # The time interval between automatic flushes, in seconds.
39     _subprocess_flush_limit = 256
40     flush_interval = 0.05
41     topic=None
42 
43     def __init__(self, session, pub_socket, name, pipe=True):
44         self.encoding = 'UTF-8'
45         self.session = session
46         self.pub_socket = pub_socket
47         self.name = name
48         self.parent_header = {}
49         self._new_buffer()
50         self._buffer_lock = threading.Lock()
51         self._master_pid = os.getpid()
52         self._master_thread = threading.current_thread().ident
53         self._pipe_pid = os.getpid()
54         self._pipe_flag = pipe
55         if pipe:
56             self._setup_pipe_in()
57     
58     def _setup_pipe_in(self):
59         """setup listening pipe for subprocesses"""
60         ctx = self.pub_socket.context
61         
62         # use UUID to authenticate pipe messages
63         self._pipe_uuid = uuid.uuid4().bytes
64         
65         self._pipe_in = ctx.socket(zmq.PULL)
66         self._pipe_in.linger = 0
67         self._pipe_port = self._pipe_in.bind_to_random_port("tcp://127.0.0.1")
68         self._pipe_poller = zmq.Poller()
69         self._pipe_poller.register(self._pipe_in, zmq.POLLIN)
70     
71     def _setup_pipe_out(self):
72         # must be new context after fork
73         ctx = zmq.Context()
74         self._pipe_pid = os.getpid()
75         self._pipe_out = ctx.socket(zmq.PUSH)
76         self._pipe_out_lock = threading.Lock()
77         self._pipe_out.connect("tcp://127.0.0.1:%i" % self._pipe_port)
78     
79     def _is_master_process(self):
80         return os.getpid() == self._master_pid
81     
82     def _is_master_thread(self):
83         return threading.current_thread().ident == self._master_thread
84     
85     def _have_pipe_out(self):
86         return os.getpid() == self._pipe_pid
87 
88     def _check_mp_mode(self):
89         """check for forks, and switch to zmq pipeline if necessary"""
90         if not self._pipe_flag or self._is_master_process():
91                 return MASTER
92         else:
93             if not self._have_pipe_out():
94                 self._flush_buffer()
95                 # setup a new out pipe
96                 self._setup_pipe_out()
97             return CHILD
98 
99     def set_parent(self, parent):
100         self.parent_header = extract_header(parent)
101 
102     def close(self):
103         self.pub_socket = None
104 
105     def _flush_from_subprocesses(self):
106         """flush possible pub data from subprocesses into my buffer"""
107         if not self._pipe_flag or not self._is_master_process():
108             return
109         for i in range(self._subprocess_flush_limit):
110             if self._pipe_poller.poll(0):
111                 msg = self._pipe_in.recv_multipart()
112                 if msg[0] != self._pipe_uuid:
113                     continue
114                 else:
115                     self._buffer.write(msg[1].decode(self.encoding, 'replace'))
116                     # this always means a flush,
117                     # so reset our timer
118                     self._start = 0
119             else:
120                 break
121     
122     def flush(self):
123         """trigger actual zmq send"""
124         if self.pub_socket is None:
125             raise ValueError(u'I/O operation on closed file')
126         
127         mp_mode = self._check_mp_mode()
128         
129         if mp_mode != CHILD:
130             # we are master
131             if not self._is_master_thread():
132                 # sub-threads must not trigger flush,
133                 # but at least they can force the timer.
134                 self._start = 0
135                 return
136             
137             self._flush_from_subprocesses()
138             data = self._flush_buffer()
139             
140             if data:
141                 content = {u'name':self.name, u'data':data}
142                 msg = self.session.send(self.pub_socket, u'stream', content=content,
143                                        parent=self.parent_header, ident=self.topic)
144             
145                 if hasattr(self.pub_socket, 'flush'):
146                     # socket itself has flush (presumably ZMQStream)
147                     self.pub_socket.flush()
148         else:
149             with self._pipe_out_lock:
150                 string = self._flush_buffer()
151                 tracker = self._pipe_out.send_multipart([
152                     self._pipe_uuid,
153                     string.encode(self.encoding, 'replace'),
154                 ], copy=False, track=True)
155                 try:
156                     tracker.wait(1)
157                 except:
158                     pass
159 
160     def isatty(self):
161         return False
162 
163     def __next__(self):
164         raise IOError('Read not supported on a write only stream.')
165 
166     if not py3compat.PY3:
167         next = __next__
168 
169     def read(self, size=-1):
170         raise IOError('Read not supported on a write only stream.')
171 
172     def readline(self, size=-1):
173         raise IOError('Read not supported on a write only stream.')
174 
175     def write(self, string):
176         if self.pub_socket is None:
177             raise ValueError('I/O operation on closed file')
178         else:
179             # Make sure that we're handling unicode
180             if not isinstance(string, unicode):
181                 string = string.decode(self.encoding, 'replace')
182             
183             is_child = (self._check_mp_mode() == CHILD)
184             self._buffer.write(string)
185             if is_child:
186                 # newlines imply flush in subprocesses
187                 # mp.Pool cannot be trusted to flush promptly (or ever),
188                 # and this helps.
189                 if '\n' in string:
190                     self.flush()
191             # do we want to check subprocess flushes on write?
192             # self._flush_from_subprocesses()
193             current_time = time.time()
194             if self._start < 0:
195                 self._start = current_time
196             elif current_time - self._start > self.flush_interval:
197                 self.flush()
198 
199     def writelines(self, sequence):
200         if self.pub_socket is None:
201             raise ValueError('I/O operation on closed file')
202         else:
203             for string in sequence:
204                 self.write(string)
205 
206     def _flush_buffer(self):
207         """clear the current buffer and return the current buffer data"""
208         data = u''
209         if self._buffer is not None:
210             data = self._buffer.getvalue()
211             self._buffer.close()
212         self._new_buffer()
213         return data
214     
215     def _new_buffer(self):
216         self._buffer = StringIO()
217         self._start = -1
218
```
--- 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/kernel/zmq/iostream.py b/IPython/kernel/zmq/iostream.py
--- a/IPython/kernel/zmq/iostream.py
+++ b/IPython/kernel/zmq/iostream.py
@@ -8,12 +8,11 @@
 #  the file COPYING, distributed as part of this software.
 #-----------------------------------------------------------------------------
 
-import sys
-import time
 import os
 import threading
+import time
 import uuid
-from io import StringIO
+from io import StringIO, UnsupportedOperation
 
 import zmq
 
@@ -171,6 +170,9 @@
 
     def readline(self, size=-1):
         raise IOError('Read not supported on a write only stream.')
+    
+    def fileno(self):
+        raise UnsupportedOperation("IOStream has no fileno.")
 
     def write(self, string):
         if self.pub_socket is None:

{"golden_diff": "diff --git a/IPython/kernel/zmq/iostream.py b/IPython/kernel/zmq/iostream.py\n--- a/IPython/kernel/zmq/iostream.py\n+++ b/IPython/kernel/zmq/iostream.py\n@@ -8,12 +8,11 @@\n #  the file COPYING, distributed as part of this software.\n #-----------------------------------------------------------------------------\n \n-import sys\n-import time\n import os\n import threading\n+import time\n import uuid\n-from io import StringIO\n+from io import StringIO, UnsupportedOperation\n \n import zmq\n \n@@ -171,6 +170,9 @@\n \n     def readline(self, size=-1):\n         raise IOError('Read not supported on a write only stream.')\n+    \n+    def fileno(self):\n+        raise UnsupportedOperation(\"IOStream has no fileno.\")\n \n     def write(self, string):\n         if self.pub_socket is None:\n", "issue": "SciPy.weave broken in IPython notebook/ qtconsole \n# Problem\n\nCompiling and running of compiled scipy.weave code is not possible with IPython notebook and IPython console. However, it works with standalone, plain IPython.\n# Minimal Example\n\nhttp://projects.scipy.org/scipy/browser/trunk/Lib/weave/examples/array3d.py?rev=1558\n# Error\n## compiling code\n\nfind the traceback here:\nhttp://pastebin.com/FdSadJtV\nfinal error:\nAttributeError: 'OutStream' object has no attribute 'fileno'\n## executing code\n\nFor both notebook and qtconsole, the output is printed in the terminal that was used to start them.\n# tested version\n## failure in\n\nipython 0.13.1\nscipy  '0.11.0' \nnumpy '1.7.0'\n## working in\n### compilation\n\nApparently it is working with numpy 1.6.0. I did not test it by myself, but that was a response on IRC. It was there also reproduced using numpy 1.7.0. I could compile it in an virtualenv using numpy 1.6 using the notebook. (Still trying to get the qtconsole to run so that I can test that)\n### output\n\nEven with numpy 1.6 the output is directed to the terminal that was used to start the IPython kernel\n\n", "before_files": [{"content": "\"\"\"wrappers for stdout/stderr forwarding over zmq\n\"\"\"\n\n#-----------------------------------------------------------------------------\n#  Copyright (C) 2013  The IPython Development Team\n#\n#  Distributed under the terms of the BSD License.  The full license is in\n#  the file COPYING, distributed as part of this software.\n#-----------------------------------------------------------------------------\n\nimport sys\nimport time\nimport os\nimport threading\nimport uuid\nfrom io import StringIO\n\nimport zmq\n\nfrom session import extract_header\n\nfrom IPython.utils import py3compat\n\n#-----------------------------------------------------------------------------\n# Globals\n#-----------------------------------------------------------------------------\n\nMASTER = 0\nCHILD = 1\n\n#-----------------------------------------------------------------------------\n# Stream classes\n#-----------------------------------------------------------------------------\n\nclass OutStream(object):\n    \"\"\"A file like object that publishes the stream to a 0MQ PUB socket.\"\"\"\n\n    # The time interval between automatic flushes, in seconds.\n    _subprocess_flush_limit = 256\n    flush_interval = 0.05\n    topic=None\n\n    def __init__(self, session, pub_socket, name, pipe=True):\n        self.encoding = 'UTF-8'\n        self.session = session\n        self.pub_socket = pub_socket\n        self.name = name\n        self.parent_header = {}\n        self._new_buffer()\n        self._buffer_lock = threading.Lock()\n        self._master_pid = os.getpid()\n        self._master_thread = threading.current_thread().ident\n        self._pipe_pid = os.getpid()\n        self._pipe_flag = pipe\n        if pipe:\n            self._setup_pipe_in()\n    \n    def _setup_pipe_in(self):\n        \"\"\"setup listening pipe for subprocesses\"\"\"\n        ctx = self.pub_socket.context\n        \n        # use UUID to authenticate pipe messages\n        self._pipe_uuid = uuid.uuid4().bytes\n        \n        self._pipe_in = ctx.socket(zmq.PULL)\n        self._pipe_in.linger = 0\n        self._pipe_port = self._pipe_in.bind_to_random_port(\"tcp://127.0.0.1\")\n        self._pipe_poller = zmq.Poller()\n        self._pipe_poller.register(self._pipe_in, zmq.POLLIN)\n    \n    def _setup_pipe_out(self):\n        # must be new context after fork\n        ctx = zmq.Context()\n        self._pipe_pid = os.getpid()\n        self._pipe_out = ctx.socket(zmq.PUSH)\n        self._pipe_out_lock = threading.Lock()\n        self._pipe_out.connect(\"tcp://127.0.0.1:%i\" % self._pipe_port)\n    \n    def _is_master_process(self):\n        return os.getpid() == self._master_pid\n    \n    def _is_master_thread(self):\n        return threading.current_thread().ident == self._master_thread\n    \n    def _have_pipe_out(self):\n        return os.getpid() == self._pipe_pid\n\n    def _check_mp_mode(self):\n        \"\"\"check for forks, and switch to zmq pipeline if necessary\"\"\"\n        if not self._pipe_flag or self._is_master_process():\n                return MASTER\n        else:\n            if not self._have_pipe_out():\n                self._flush_buffer()\n                # setup a new out pipe\n                self._setup_pipe_out()\n            return CHILD\n\n    def set_parent(self, parent):\n        self.parent_header = extract_header(parent)\n\n    def close(self):\n        self.pub_socket = None\n\n    def _flush_from_subprocesses(self):\n        \"\"\"flush possible pub data from subprocesses into my buffer\"\"\"\n        if not self._pipe_flag or not self._is_master_process():\n            return\n        for i in range(self._subprocess_flush_limit):\n            if self._pipe_poller.poll(0):\n                msg = self._pipe_in.recv_multipart()\n                if msg[0] != self._pipe_uuid:\n                    continue\n                else:\n                    self._buffer.write(msg[1].decode(self.encoding, 'replace'))\n                    # this always means a flush,\n                    # so reset our timer\n                    self._start = 0\n            else:\n                break\n    \n    def flush(self):\n        \"\"\"trigger actual zmq send\"\"\"\n        if self.pub_socket is None:\n            raise ValueError(u'I/O operation on closed file')\n        \n        mp_mode = self._check_mp_mode()\n        \n        if mp_mode != CHILD:\n            # we are master\n            if not self._is_master_thread():\n                # sub-threads must not trigger flush,\n                # but at least they can force the timer.\n                self._start = 0\n                return\n            \n            self._flush_from_subprocesses()\n            data = self._flush_buffer()\n            \n            if data:\n                content = {u'name':self.name, u'data':data}\n                msg = self.session.send(self.pub_socket, u'stream', content=content,\n                                       parent=self.parent_header, ident=self.topic)\n            \n                if hasattr(self.pub_socket, 'flush'):\n                    # socket itself has flush (presumably ZMQStream)\n                    self.pub_socket.flush()\n        else:\n            with self._pipe_out_lock:\n                string = self._flush_buffer()\n                tracker = self._pipe_out.send_multipart([\n                    self._pipe_uuid,\n                    string.encode(self.encoding, 'replace'),\n                ], copy=False, track=True)\n                try:\n                    tracker.wait(1)\n                except:\n                    pass\n\n    def isatty(self):\n        return False\n\n    def __next__(self):\n        raise IOError('Read not supported on a write only stream.')\n\n    if not py3compat.PY3:\n        next = __next__\n\n    def read(self, size=-1):\n        raise IOError('Read not supported on a write only stream.')\n\n    def readline(self, size=-1):\n        raise IOError('Read not supported on a write only stream.')\n\n    def write(self, string):\n        if self.pub_socket is None:\n            raise ValueError('I/O operation on closed file')\n        else:\n            # Make sure that we're handling unicode\n            if not isinstance(string, unicode):\n                string = string.decode(self.encoding, 'replace')\n            \n            is_child = (self._check_mp_mode() == CHILD)\n            self._buffer.write(string)\n            if is_child:\n                # newlines imply flush in subprocesses\n                # mp.Pool cannot be trusted to flush promptly (or ever),\n                # and this helps.\n                if '\\n' in string:\n                    self.flush()\n            # do we want to check subprocess flushes on write?\n            # self._flush_from_subprocesses()\n            current_time = time.time()\n            if self._start < 0:\n                self._start = current_time\n            elif current_time - self._start > self.flush_interval:\n                self.flush()\n\n    def writelines(self, sequence):\n        if self.pub_socket is None:\n            raise ValueError('I/O operation on closed file')\n        else:\n            for string in sequence:\n                self.write(string)\n\n    def _flush_buffer(self):\n        \"\"\"clear the current buffer and return the current buffer data\"\"\"\n        data = u''\n        if self._buffer is not None:\n            data = self._buffer.getvalue()\n            self._buffer.close()\n        self._new_buffer()\n        return data\n    \n    def _new_buffer(self):\n        self._buffer = StringIO()\n        self._start = -1\n", "path": "IPython/kernel/zmq/iostream.py"}], "after_files": [{"content": "\"\"\"wrappers for stdout/stderr forwarding over zmq\n\"\"\"\n\n#-----------------------------------------------------------------------------\n#  Copyright (C) 2013  The IPython Development Team\n#\n#  Distributed under the terms of the BSD License.  The full license is in\n#  the file COPYING, distributed as part of this software.\n#-----------------------------------------------------------------------------\n\nimport os\nimport threading\nimport time\nimport uuid\nfrom io import StringIO, UnsupportedOperation\n\nimport zmq\n\nfrom session import extract_header\n\nfrom IPython.utils import py3compat\n\n#-----------------------------------------------------------------------------\n# Globals\n#-----------------------------------------------------------------------------\n\nMASTER = 0\nCHILD = 1\n\n#-----------------------------------------------------------------------------\n# Stream classes\n#-----------------------------------------------------------------------------\n\nclass OutStream(object):\n    \"\"\"A file like object that publishes the stream to a 0MQ PUB socket.\"\"\"\n\n    # The time interval between automatic flushes, in seconds.\n    _subprocess_flush_limit = 256\n    flush_interval = 0.05\n    topic=None\n\n    def __init__(self, session, pub_socket, name, pipe=True):\n        self.encoding = 'UTF-8'\n        self.session = session\n        self.pub_socket = pub_socket\n        self.name = name\n        self.parent_header = {}\n        self._new_buffer()\n        self._buffer_lock = threading.Lock()\n        self._master_pid = os.getpid()\n        self._master_thread = threading.current_thread().ident\n        self._pipe_pid = os.getpid()\n        self._pipe_flag = pipe\n        if pipe:\n            self._setup_pipe_in()\n    \n    def _setup_pipe_in(self):\n        \"\"\"setup listening pipe for subprocesses\"\"\"\n        ctx = self.pub_socket.context\n        \n        # use UUID to authenticate pipe messages\n        self._pipe_uuid = uuid.uuid4().bytes\n        \n        self._pipe_in = ctx.socket(zmq.PULL)\n        self._pipe_in.linger = 0\n        self._pipe_port = self._pipe_in.bind_to_random_port(\"tcp://127.0.0.1\")\n        self._pipe_poller = zmq.Poller()\n        self._pipe_poller.register(self._pipe_in, zmq.POLLIN)\n    \n    def _setup_pipe_out(self):\n        # must be new context after fork\n        ctx = zmq.Context()\n        self._pipe_pid = os.getpid()\n        self._pipe_out = ctx.socket(zmq.PUSH)\n        self._pipe_out_lock = threading.Lock()\n        self._pipe_out.connect(\"tcp://127.0.0.1:%i\" % self._pipe_port)\n    \n    def _is_master_process(self):\n        return os.getpid() == self._master_pid\n    \n    def _is_master_thread(self):\n        return threading.current_thread().ident == self._master_thread\n    \n    def _have_pipe_out(self):\n        return os.getpid() == self._pipe_pid\n\n    def _check_mp_mode(self):\n        \"\"\"check for forks, and switch to zmq pipeline if necessary\"\"\"\n        if not self._pipe_flag or self._is_master_process():\n                return MASTER\n        else:\n            if not self._have_pipe_out():\n                self._flush_buffer()\n                # setup a new out pipe\n                self._setup_pipe_out()\n            return CHILD\n\n    def set_parent(self, parent):\n        self.parent_header = extract_header(parent)\n\n    def close(self):\n        self.pub_socket = None\n\n    def _flush_from_subprocesses(self):\n        \"\"\"flush possible pub data from subprocesses into my buffer\"\"\"\n        if not self._pipe_flag or not self._is_master_process():\n            return\n        for i in range(self._subprocess_flush_limit):\n            if self._pipe_poller.poll(0):\n                msg = self._pipe_in.recv_multipart()\n                if msg[0] != self._pipe_uuid:\n                    continue\n                else:\n                    self._buffer.write(msg[1].decode(self.encoding, 'replace'))\n                    # this always means a flush,\n                    # so reset our timer\n                    self._start = 0\n            else:\n                break\n    \n    def flush(self):\n        \"\"\"trigger actual zmq send\"\"\"\n        if self.pub_socket is None:\n            raise ValueError(u'I/O operation on closed file')\n        \n        mp_mode = self._check_mp_mode()\n        \n        if mp_mode != CHILD:\n            # we are master\n            if not self._is_master_thread():\n                # sub-threads must not trigger flush,\n                # but at least they can force the timer.\n                self._start = 0\n                return\n            \n            self._flush_from_subprocesses()\n            data = self._flush_buffer()\n            \n            if data:\n                content = {u'name':self.name, u'data':data}\n                msg = self.session.send(self.pub_socket, u'stream', content=content,\n                                       parent=self.parent_header, ident=self.topic)\n            \n                if hasattr(self.pub_socket, 'flush'):\n                    # socket itself has flush (presumably ZMQStream)\n                    self.pub_socket.flush()\n        else:\n            with self._pipe_out_lock:\n                string = self._flush_buffer()\n                tracker = self._pipe_out.send_multipart([\n                    self._pipe_uuid,\n                    string.encode(self.encoding, 'replace'),\n                ], copy=False, track=True)\n                try:\n                    tracker.wait(1)\n                except:\n                    pass\n\n    def isatty(self):\n        return False\n\n    def __next__(self):\n        raise IOError('Read not supported on a write only stream.')\n\n    if not py3compat.PY3:\n        next = __next__\n\n    def read(self, size=-1):\n        raise IOError('Read not supported on a write only stream.')\n\n    def readline(self, size=-1):\n        raise IOError('Read not supported on a write only stream.')\n    \n    def fileno(self):\n        raise UnsupportedOperation(\"IOStream has no fileno.\")\n\n    def write(self, string):\n        if self.pub_socket is None:\n            raise ValueError('I/O operation on closed file')\n        else:\n            # Make sure that we're handling unicode\n            if not isinstance(string, unicode):\n                string = string.decode(self.encoding, 'replace')\n            \n            is_child = (self._check_mp_mode() == CHILD)\n            self._buffer.write(string)\n            if is_child:\n                # newlines imply flush in subprocesses\n                # mp.Pool cannot be trusted to flush promptly (or ever),\n                # and this helps.\n                if '\\n' in string:\n                    self.flush()\n            # do we want to check subprocess flushes on write?\n            # self._flush_from_subprocesses()\n            current_time = time.time()\n            if self._start < 0:\n                self._start = current_time\n            elif current_time - self._start > self.flush_interval:\n                self.flush()\n\n    def writelines(self, sequence):\n        if self.pub_socket is None:\n            raise ValueError('I/O operation on closed file')\n        else:\n            for string in sequence:\n                self.write(string)\n\n    def _flush_buffer(self):\n        \"\"\"clear the current buffer and return the current buffer data\"\"\"\n        data = u''\n        if self._buffer is not None:\n            data = self._buffer.getvalue()\n            self._buffer.close()\n        self._new_buffer()\n        return data\n    \n    def _new_buffer(self):\n        self._buffer = StringIO()\n        self._start = -1\n", "path": "IPython/kernel/zmq/iostream.py"}]}