- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我应该如何从 Python 3 的 Circuits 框架 Controller 中的一个方法中获取多个 URL?这是我想要的一个简单示例,除了 urllib3。最好在开始时请求两个 URL,当它们都返回时,继续执行。
# -*- coding: utf-8 -*-
__author__ = 'jscarbor'
import urllib3
from circuits.web import Server, Controller, Static
http = urllib3.PoolManager()
class Root(Controller):
def index(self):
self.response.headers["Content-Type"] = "text/plain"
a = http.request('GET', 'https://www.w3.org/services/html2txt?url=http%3A%2F%2Fwww.example.com%2F').data
b = http.request('GET', 'http://home.hiwaay.net/~jimes/checklist.txt').data
return "%s %s" % (a, b)
(Server(8011) + Root()).run()
最佳答案
您需要使用与 Controller 不同的 channel 将 circuits.web.client.Client 组件注册到您的 Controller (因为事件名称在客户端和服务器组件中相同)。然后您可以将请求事件发送到此 channel 并等待响应。在您的特定示例中,您需要为请求事件注册一个处理程序以挂接到响应过程。我目前没有工作示例,但这是一个起点的基础:
from circuits.web.client import Client, request as request_event
from circuits.web import Server, Controller
from circuits import handler
class Root(Controller):
@handler('request')
def _on_request(self):
a = yield self.wait(request_event('GET', 'https://www.w3.org/services/html2txt?url=http%3A%2F%2Fwww.example.com%2F'), channel='url-fetching')
b = yield self.wait((request_event('GET', 'http://home.hiwaay.net/~jimes/checklist.txt'), channel='url-fetching')
self.response.headers["Content-Type"] = "text/plain"
self.response.body = "%s %s" % (a.value.read(), b.value.read())
(Server(('0.0.0.0', 8011)) + Root() + Client(channel='url-fetching').run()
关于python - 我应该如何从电路框架中获取其他 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41883179/
我有一个骨架化的体素结构,如下所示: 实际结构比这个例子大很多有没有办法找到结构中的闭环?我尝试将其转换为图形并使用基于图形的方法,但它们都存在图形没有节点位置的空间信息的问题,因此图形可以具有多个同
我正在尝试使用 Stem 启动 Tor 连接,然后列出所选的节点。 使用他们网站上的其他问题和常见问题解答,我可以做其中之一,但不能同时做。 例如,我可以启动一个 Tor 电路 tor_proce
问题如下:考虑三个输入 A、B、C,找到一个带有 AND、OR 和 NOT 门的 bool 电路,使得输出不是(A),不是(B),不是(C),最多使用 2 个 NOT盖茨。 我想用prolog找到电路
我连接了两个按钮和五个 LED。在电路中它的顺序是按钮,五个LED和按钮。 LED 的顺序从左到右(从第一个按钮开始)红色、绿色、蓝色、绿色和红色。我使用蓝色(中间)LED 来区分左侧和右侧。按下左按
我是一名优秀的程序员,十分优秀!