From 8d80f611bfeb1d2f97a6e47797c30ab2630354e2 Mon Sep 17 00:00:00 2001 From: rep Date: Wed, 10 Oct 2012 14:04:14 +0200 Subject: [PATCH 1/2] gevent inputhook --- IPython/core/shellapp.py | 4 ++-- IPython/lib/inputhook.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/IPython/core/shellapp.py b/IPython/core/shellapp.py index 5c57228d566..5c720ce4476 100644 --- a/IPython/core/shellapp.py +++ b/IPython/core/shellapp.py @@ -165,8 +165,8 @@ def _extra_extension_changed(self, name, old, new): module_to_run = Unicode('', config=True, help="Run the module as a script." ) - gui = CaselessStrEnum(('qt', 'wx', 'gtk', 'glut', 'pyglet', 'osx'), config=True, - help="Enable GUI event loop integration ('qt', 'wx', 'gtk', 'glut', 'pyglet', 'osx')." + gui = CaselessStrEnum(('qt', 'wx', 'gtk', 'glut', 'pyglet', 'osx', 'gevent'), config=True, + help="Enable GUI event loop integration ('qt', 'wx', 'gtk', 'glut', 'pyglet', 'osx', 'gevent')." ) pylab = CaselessStrEnum(['tk', 'qt', 'wx', 'gtk', 'osx', 'inline', 'auto'], config=True, diff --git a/IPython/lib/inputhook.py b/IPython/lib/inputhook.py index b0e9a6780ef..613e3c74c86 100644 --- a/IPython/lib/inputhook.py +++ b/IPython/lib/inputhook.py @@ -38,6 +38,7 @@ GUI_GLUT = 'glut' GUI_PYGLET = 'pyglet' GUI_GTK3 = 'gtk3' +GUI_GEVENT = 'gevent' GUI_NONE = 'none' # i.e. disable #----------------------------------------------------------------------------- @@ -457,6 +458,22 @@ def disable_gtk3(self): """ self.clear_inputhook() + def enable_gevent(self, app=None): + """ gevent """ + from gevent.monkey import patch_all + from gevent.socket import wait_read + + def inputhook_gevent(): + wait_read(sys.stdin.fileno()) + return 0 + + self.set_inputhook(inputhook_gevent) + self._current_gui = GUI_GEVENT + return app + + def disable_gevent(self): + self.clear_inputhook() + def current_gui(self): """Return a string indicating the currently active GUI or None.""" return self._current_gui @@ -477,6 +494,8 @@ def current_gui(self): disable_pyglet = inputhook_manager.disable_pyglet enable_gtk3 = inputhook_manager.enable_gtk3 disable_gtk3 = inputhook_manager.disable_gtk3 +enable_gevent = inputhook_manager.enable_gevent +disable_gevent = inputhook_manager.disable_gevent clear_inputhook = inputhook_manager.clear_inputhook set_inputhook = inputhook_manager.set_inputhook current_gui = inputhook_manager.current_gui @@ -519,6 +538,7 @@ def enable_gui(gui=None, app=None): GUI_GLUT: enable_glut, GUI_PYGLET: enable_pyglet, GUI_GTK3: enable_gtk3, + GUI_GEVENT: enable_gevent, } try: gui_hook = guis[gui] From a69e8717234674878884cd7e4ec36c04b7aecdcb Mon Sep 17 00:00:00 2001 From: rep Date: Wed, 10 Oct 2012 14:41:22 +0200 Subject: [PATCH 2/2] no monkeypatching (patching threading actually screws up ipython history) --- IPython/lib/inputhook.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/IPython/lib/inputhook.py b/IPython/lib/inputhook.py index 613e3c74c86..584cd21471f 100644 --- a/IPython/lib/inputhook.py +++ b/IPython/lib/inputhook.py @@ -459,8 +459,7 @@ def disable_gtk3(self): self.clear_inputhook() def enable_gevent(self, app=None): - """ gevent """ - from gevent.monkey import patch_all + """gevent integration""" from gevent.socket import wait_read def inputhook_gevent():