I use:
python3.7
,
web3==4.9.2
,
Infura
and/or own Node
.
After web3
was initialized it returns isConnected()
response only in first time, after that it freezes.
web3.py:
from web3 import Web3
from web3.gas_strategies.rpc import rpc_gas_price_strategy
from web3.providers.auto import load_provider_from_uri
class Web3NotAvailableException(Exception):
def __init__(self, rpc_url):
self.rpc_url = rpc_url
def __str__(self):
return f'WEB3_RPC_URL: {self.rpc_url}'
def get_web3():
logger.debug('Getting web3 instance')
if hasattr(get_web3, '_web3_instance'):
logger.warn('Here 1')
_web3_instance = getattr(get_web3, '_web3_instance')
else:
logger.warn('Here 2')
_web3_instance = Web3(load_provider_from_uri(settings.WEB3_RPC_URL))
_web3_instance.eth.setGasPriceStrategy(rpc_gas_price_strategy)
setattr(get_web3, '_web3_instance', _web3_instance)
logger.warn('Before isConnected()')
if not _web3_instance.isConnected():
logger.warn('Here 3')
_web3_instance = None
raise Web3NotAvailableException(settings.WEB3_RPC_URL)
logger.warn('Finish')
return _web3_instance
logs:
DEBUG 07/06/2021 16:30:13 | [ web3.py:46 ] Getting web3 instance
WARNING 07/06/2021 16:30:13 | [ web3.py:51 ] Here 2
WARNING 07/06/2021 16:30:13 | [ web3.py:56 ] Before isConnected()
WARNING 07/06/2021 16:30:13 | [ web3.py:62 ] Finish
DEBUG 07/06/2021 16:30:15 | [ web3.py:46 ] Getting web3 instance
WARNING 07/06/2021 16:30:15 | [ web3.py:48 ] Here 1
WARNING 07/06/2021 16:30:15 | [ web3.py:56 ] Before isConnected()
and after that docker container freezes and happen nothing. Although celery
should pushes tasks every 30 sec.
But if i use ganache locally everything works.
DEBUG 07/06/2021 16:59:37 | [ web3.py:46 ] Getting web3 instance
WARNING 07/06/2021 16:59:37 | [ web3.py:51 ] Here 2
WARNING 07/06/2021 16:59:37 | [ web3.py:56 ] Before isConnected()
WARNING 07/06/2021 16:59:37 | [ web3.py:62 ] Finish
################################################
DEBUG 07/06/2021 17:00:11 | [ web3.py:46 ] Getting web3 instance
WARNING 07/06/2021 17:00:11 | [ web3.py:48 ] Here 1
WARNING 07/06/2021 17:00:11 | [ web3.py:56 ] Before isConnected()
WARNING 07/06/2021 17:00:11 | [ web3.py:62 ] Finish
################################################
DEBUG 07/06/2021 17:00:41 | [ web3.py:46 ] Getting web3 instance
WARNING 07/06/2021 17:00:41 | [ web3.py:48 ] Here 1
WARNING 07/06/2021 17:00:41 | [ web3.py:56 ] Before isConnected()
WARNING 07/06/2021 17:00:41 | [ web3.py:62 ] Finish
What wrong ?