Python 多个事件筛选器不适用于Infura
我正在尝试聆听英弗拉的许多事件,但它不起作用。只有一个过滤器工作,当我添加第二个过滤器时,出现以下消息:Python 多个事件筛选器不适用于Infura,python,multithreading,web3py,Python,Multithreading,Web3py,我正在尝试聆听英弗拉的许多事件,但它不起作用。只有一个过滤器工作,当我添加第二个过滤器时,出现以下消息: RuntimeError: cannot call recv while another coroutine is already waiting for the next message Exception in thread Thread-15: raise ValueError(response["error"]) ValueError: {'code': -32
RuntimeError: cannot call recv while another coroutine is already waiting for the next message
Exception in thread Thread-15:
raise ValueError(response["error"])
ValueError: {'code': -32000, 'message': 'filter not found'}
大约2秒钟后,出现以下错误消息:
RuntimeError: cannot call recv while another coroutine is already waiting for the next message
Exception in thread Thread-15:
raise ValueError(response["error"])
ValueError: {'code': -32000, 'message': 'filter not found'}
下面是我的python代码:
import threading
import time
from web3 import Web3
import json
PROVIDER = "wss://ropsten.infura.io/ws/v3/f5000000000000"
web3 = Web3(Web3.WebsocketProvider(PROVIDER))
truffleFile = json.load(open('/Users/a/ropsten/build/contracts/a.json'))
abi = truffleFile['abi']
bytecode = truffleFile['bytecode']
contract = web3.eth.contract(abi= abi, address= '0x000000000000000')
# ------------------------------------------------------------
def handle_event2(name,event):
print('the event is from :%s'%name)
print(event)
def log_loop2(name,event_filter, poll_interval):
while True:
for event in event_filter.get_new_entries():
handle_event2(name,event)
time.sleep(poll_interval)
def PS_listen():
print(" I am in PS Listen ")
block_filter = contract.events.PS.createFilter(fromBlock = 'latest')
worker1 = threading.Thread(target=log_loop2, args=('Th-1',block_filter, 2,))
worker1.start()
print(" I am in PS Listen after start")
def handle_event2(name,event):
print('the event is from :%s'%name)
print(event)
# ---------------------------------------------
def log_loop2(name,event_filter, poll_interval):
while True:
for event in event_filter.get_new_entries():
handle_event2(name,event)
time.sleep(poll_interval)
def listen():
print(" I am in Listen ")
block_filter = contract.events.PS.createFilter(fromBlock = 'latest')
print(block_filter)
worker2 = threading.Thread(target=log_loop2, args=('Th-2',block_filter, 2,))
worker2.start
print(" I am in Listen after start")
print(" This is the main function1")
PS_listen()
listen()
print(" This is the main function2")
注意:我已经正确添加了Infura项目ID。合同地址在Ropsten infura上部署后从终端进行复制
是线程问题阻止我为下一个事件创建另一个过滤器,而错误意味着协同程序正在另一个任务中运行吗
非常感谢您的帮助