Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
724 views
in Technique[技术] by (71.8m points)

flask - Celery task hangs when calling a web3 contract function via websocket

The following code runs fine in my flask server, but when run by a celery worker it hangs.

from web3.auto.infura import w3

contract = w3.eth.contract(checksum_address, abi=abi)
decimals = contract.functions.decimals().call()

The DEBUG celery worker logs show

[2021-01-05 23:11:16,699: DEBUG/ForkPoolWorker-5] Making request. Method: eth_call
[2021-01-05 23:11:16,701: DEBUG/ForkPoolWorker-5] Making request WebSocket. URI: wss://mainnet.infura.io/ws/v3/<my project id>, Method: eth_call

I'm not very familiar with websockets, and after looking through the web3.py github issues, I noticed a few people mentioning that they use asyncio instead of celery for async operations with web3.py. I'm wondering if this is a celery configuration issue, a web3.py configuration issue, or maybe more simply, a poor choice of libraries.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...