我编写了一个客户端来处理较低级别的TLS连接参数,如ClientHellos等
我是在围棋里做的,因为那里容易多了。我的主程序(webscraper)是用Python编写的。我通过ctypes通过DLL将Go源代码连接到Python文件。到目前为止,我的webscraper结构是异步的,一次可以处理多个连接
不幸的是,我的Go客户端不是异步的。是否有一种方法可以在Python中更改它,使它异步等待ctypes指针的响应,直到它出现?现在它正在等待响应,但同时会阻止所有其他代码的执行
编辑: 下面的代码示例
async def request(self, method, url, headers, body=None, rawBody=None, pseudoHeaderOrder=["method", "authority", "scheme", "path"]):
global httpLib
global initFunc
global requestFunc
global changeProxyFunc
global freePointerFunc
config = {
"id": self.cid,
"method": method.upper(),
"timeout": 20000,
"url": url,
"pseudoHeaderOrder": pseudoHeaderOrder,
"headers": headers
}
#Critical
if body:
config["body"] = body
if rawBody:
rawBody = [b for b in bytes(rawBody, "utf-8")]
config["rawBody"] = rawBody
config = json.dumps(config)
#print(config)
#THIS PART CASTS THE REQUEST
ptr = requestFunc(config.encode('utf-8'))
string = ctypes.cast(ptr, ctypes.c_char_p).value.decode("utf-8")
#THIS PART CLEARS THE POINTER
freePointerFunc(ptr)
#...
可以使用executor将阻塞调用移动到单独的线程/进程
这样应该行得通
相关问题 更多 >
编程相关推荐