- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 http://eventlet.net/doc/examples.html 上运行第一个代码示例,webcrawler.py
:
#!/usr/bin/env python
"""
This is a simple web "crawler" that fetches a bunch of urls using a pool to
control the number of outbound connections. It has as many simultaneously open
connections as coroutines in the pool.
The prints in the body of the fetch function are there to demonstrate that the
requests are truly made in parallel.
"""
import eventlet
from eventlet.green import urllib2
urls = [
"https://www.google.com/intl/en_ALL/images/logo.gif",
"http://python.org/images/python-logo.gif",
"http://us.i1.yimg.com/us.yimg.com/i/ww/beta/y3.gif",
]
def fetch(url):
print("opening", url)
body = urllib2.urlopen(url).read()
print("done with", url)
return url, body
pool = eventlet.GreenPool(200)
for url, body in pool.imap(fetch, urls):
print("got body from", url, "of length", len(body))
但是,这会导致
ModuleNotFoundError: No module named 'urllib2'
我使用的是 eventlet 版本 0.21.0。该模块已移至 eventlet 中吗?
最佳答案
这些示例似乎已经过时(现在更是如此)。
对于 python 2,使用这个:
import eventlet
from eventlet.green import urllib2 as request
request.urlopen(...)
对于 python 3,使用这个:
import eventlet
from eventlet.green.urllib import request
request.urlopen(...)
关于python - 未找到 eventlet.green.urllib2 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47171621/
我正在使用 eventlet celery 工作线程,想知道在我的任务之一中使用绿色线程池是否安全。 最佳答案 当然,这是安全的。万一您遇到任何问题,请在此处报告 https://github.com
我正在循环一个列表并对列表中的每个成员执行一些操作。如果某个成员花费了太多时间(在本例中为 1 秒),我打算跳过它。但是,try 语句内的 block 始终处于处理状态,并且永远不会超时。我不明白为什
我是 python 线程的新手,尝试使用 eventlet 线程,我编写了一个简单的程序来计算数字的平方和立方,并在其上发出两个 eventlet 线程。我的代码如下: import even
import eventlet def foo(): print('foo') def main(): eventlet.monkey_patch() pool = event
我编写了以下代码: import eventlet import requests import redis redis = redis.StrictRedis(host="localhost", p
既然Eventlet使用了绿色线程和异步I/O,那么在访问对象之前还需要设置锁吗?我的理解是 greenlets 都是一个线程的一部分,不需要锁定。谁能证实或否认这一点? 最佳答案 您的理解是正确的:
根据我的理解,线程不能并行执行(基于可用性和随机性执行),这就是使用 Eventlet 的原因。 如果 Eventlets 更适合并行性,为什么我们不能只使用 Python 的多处理模块。 我想到了执
我有 2 个 celery worker,它们通过 eventlet 进行池化,配置如下: celery multi start w1 w2 -A proj -l info --time-limit=
我对 eventlet 很陌生,对 sleep() 有一些疑问 我用一小段代码进行了测试。 一开始我spawn了3个greenthread,然后调用了greenthread.sleep(0),然后这3
当使用 --pool=eventlet 选项运行我的 celery worker 时,我从 amqplib.client_0_8.method_framing.read_method 收到了很多“IO
如果我使用具有 Eventlet 工作类型的 Gunicorn 部署 Django,并且只使用一个进程,那么在为 1000 个(默认)工作连接提供服务时会发生什么? Django 的哪些部分被复制到每
我想了解 eventlet.tpool 有什么用。文档说 tpool.execute() 允许您获取阻塞函数并在新线程中运行它。但是,tpool.execute() 方法本身会阻塞,直到线程完成!那么
作为mentioned in the celery docs ,对于事件 I/O(例如异步 HTTP 请求),eventlet 池应该比 prefork 池更快。 他们甚至提到了这一点 "In an
我想多线程发送邮件(使用 django 的 SMTPConnection 或者 smtplib 模块)。我希望有一个类似于 urllib2 的模块,我可以: import eventlet from
我有一个程序可以与 postgresql 服务器保持持久连接。假设由于网络问题导致连接被阻塞(可以通过关闭网络接口(interface)来模拟),使用 eventlet 调用查询的进程就会卡住。这也阻
****大家好 我正在使用 eventlet 来实现网络爬虫。我的代码是这样的 import eventlet urls = [ "http://deeplearning.stanford.e
我正在为数据分析任务编写网络用户界面。 这是它应该工作的方式: 在用户指定dataset和learning rate等参数后,我创建了一个新的task record,然后启动了这个任务的执行器异步(执
我在 celery workers 中使用 Python requests 进行大量(~10/秒)API 调用(包括 GET、POST、PUT、DELETE)。每个请求大约需要 5-10 秒才能完成。
我目前正在进行的项目使用 Flask-SocketIO 在我的 Raspberry Pi 和连接到它所服务的网站的客户端之间进行通信。但是,一旦我设置了一个或多个额外线程,就会发生错误。我使用猴子补丁
我需要注入(inject)线程级上下文信息以进行日志记录和调试。有人告诉我这可能不安全。 greenthread = worker_pool.spawn(run_worker, args, handl
我是一名优秀的程序员,十分优秀!