##// END OF EJS Templates
Merge pull request #2868 from takluyver/import-performance...
Merge pull request #2868 from takluyver/import-performance Import performance Defer various imports for a small reduction in startup time. IPython.lib.__init__ previously loaded IPython.lib.inputhook to export some of its functions. This meant that importing anything from IPython.lib also loaded inputhook. For now, I've just removed that import, but that is an API change, because the functions are no longer accessible as e.g. IPython.lib.enable_qt4 Added a note about the API change. Timing command, borrowed from Openoffice to simulate cold start: $ sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches; time ipython3 -c pass Results with this branch: 7.68, 7.64, 7.35, 7.38 s 'real' Results with master: 8.17, 8.04, 7.81, 7.77

File last commit:

r4574:a8c54759
r9459:ff3032f2 merge
Show More
win32support.py
72 lines | 2.1 KiB | text/x-python | PythonLexer
"""Utility for forwarding file read events over a zmq socket.
This is necessary because select on Windows only supports sockets, not FDs.
Authors:
* MinRK
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2011 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import uuid
import zmq
from threading import Thread
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
class ForwarderThread(Thread):
def __init__(self, sock, fd):
Thread.__init__(self)
self.daemon=True
self.sock = sock
self.fd = fd
def run(self):
"""Loop through lines in self.fd, and send them over self.sock."""
line = self.fd.readline()
# allow for files opened in unicode mode
if isinstance(line, unicode):
send = self.sock.send_unicode
else:
send = self.sock.send
while line:
send(line)
line = self.fd.readline()
# line == '' means EOF
self.fd.close()
self.sock.close()
def forward_read_events(fd, context=None):
"""Forward read events from an FD over a socket.
This method wraps a file in a socket pair, so it can
be polled for read events by select (specifically zmq.eventloop.ioloop)
"""
if context is None:
context = zmq.Context.instance()
push = context.socket(zmq.PUSH)
push.setsockopt(zmq.LINGER, -1)
pull = context.socket(zmq.PULL)
addr='inproc://%s'%uuid.uuid4()
push.bind(addr)
pull.connect(addr)
forwarder = ForwarderThread(push, fd)
forwarder.start()
return pull
__all__ = ['forward_read_events']