async def subscribe_to_new_block_head():
async with AsyncWeb3(WebSocketProvider(WS_PROVIDER_URL)) as w3:
await w3.eth.subscribe("newHeads")
async for response in w3.socket.process_subscriptions():
print(response)
if name == "main":
asyncio.run(subscribe_to_new_block_head())
* The full output of the error
Not an error, but 100% CPU usage can be observed
* What type of node you were connecting to.
Ethereum mainnet
### How can it be fixed?
---
Making RequestProcessor.pop_raw_response an async function, await pop_raw_response instead of polling it.
**Note:** We prefer to use issues to track our work. If you think you've encountered a bug in web3py or
have a feature request, you're in the right place. If you have implementation or usage questions,
please refer to our [documentation](https://web3py.readthedocs.io/en/latest/) and/or join the conversation
on [discord](https://discord.gg/GHryRvPB84).
pip freeze
outputWhat was wrong?
Please include any of the following that are applicable:
WS_PROVIDER_URL = "wss://eth-mainnet.ws.alchemyapi.io/ws/demo"
async def subscribe_to_new_block_head(): async with AsyncWeb3(WebSocketProvider(WS_PROVIDER_URL)) as w3: await w3.eth.subscribe("newHeads") async for response in w3.socket.process_subscriptions(): print(response)
if name == "main": asyncio.run(subscribe_to_new_block_head())