有没有办法在ipython笔记本中使用gevent?

时间:2015-07-23 20:35:51

标签: python ipython ipython-notebook gevent

我正在使用导入gevent的库。我想在ipython笔记本中运行它。我的第一个单元格是:

print 'foo'
import library
print 'bar'

但是没有印刷品发生。我想库补丁线程,否则它应该工作:https://github.com/ipython/ipython/issues/2785/#issuecomment-48009193

我的ipython文件(/usr/local/bin/ipython)如下所示:

#!/usr/bin/python

# -*- coding: utf-8 -*-
import re
import sys

from IPython import start_ipython

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(start_ipython())

我尝试在顶部使用猴子修补程序运行它的副本,基于这里的提示:https://github.com/ipython/ipython/issues/4771。 ipython加载很好,但ipython笔记本不起作用。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

在python shell中以交互方式尝试这样的事情。当它运行时,然后创建需要从命令行运行的脚本。

python3
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import IPython
>>> IPython.start_ipython (argv = ['notebook', '--no-browser'])
[I 17:31:43.672 NotebookApp] Using MathJax from CDN: https://cdn.mathjax.org/mathjax/latest/MathJax.js
[I 17:31:43.709 NotebookApp] The port 8888 is already in use, trying another random port.
[W 17:31:43.712 NotebookApp] Terminals not available (error was No module named 'terminado')
[I 17:31:43.713 NotebookApp] Serving notebooks from local directory: /Users/fred/Dropbox/notebooks
[I 17:31:43.713 NotebookApp] 0 active kernels 
[I 17:31:43.713 NotebookApp] The IPython Notebook is running at: http://localhost:8889/
[I 17:31:43.713 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

--no-browser选项可以避免直接启动浏览器。如果您希望本地浏览器自动启动,请忽略。在此示例中,您可以将浏览器指向http://localhost:8889/。通常默认情况下,它将在端口8888上。