RafaelWO / unparallel

Create async web requests via Python in no time.
https://rafaelwo.github.io/unparallel/
MIT License
10 stars 0 forks source link

UP function does nothing #157

Closed claytonneal closed 3 months ago

claytonneal commented 7 months ago

🐛 Bug Report

The progress bar is stuck at 0% and no http requests are made

🔬 How To Reproduce

Steps to reproduce the behavior:

Code sample

async def index_blocks(block_from: int, block_to: int):
    """Index a block range"""
    global TOTAL_TXS, TOTAL_REVERTED_TXS
    print(f"Indexing blocks from {block_from} to {block_to}")
    urls = [f"blocks/{block}?expanded=true" for block in range(block_from, block_to)]
    block_responses = await up(urls, method="GET", base_url=THOR_URL, timeout=5, max_retries_on_timeout=2)

def get_contract_txs():
    best_block = get_best_block()
    loop = asyncio.new_event_loop()
    index_from = best_block - (INDEX_DAYS * BLOCKS_PER_DAY)
    loop.run_until_complete(index_blocks(index_from, best_block))

def main():
    get_contract_txs()
    print(f"Total transactions for VOT3 or B3TR: {TOTAL_TXS}")
    print(f"Total transactions reverted: {TOTAL_REVERTED_TXS}")
    print(f"Clauses to debug trace: {len(REVERTED_TXS)}")

if __name__ == '__main__':
    main()

Environment

Screenshots

📈 Expected behavior

📎 Additional context

github-actions[bot] commented 7 months ago

Hello @claytonneal, thank you for your interest in our work!

If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

RafaelWO commented 7 months ago

Hey @claytonneal, can you provide a minimal reproducible example that I can run? (I don't know the values of the global variables in your example.) Maybe you can also add the output you get when running your code.

I hope we can resolve your issue together :slightly_smiling_face:

RafaelWO commented 7 months ago

@claytonneal I managed to run your code with some modifications - essentially providing dummy values for your global variables and targeting https://httpbin.org/ - and it works without issues:

import asyncio

from unparallel import up

THOR_URL = "https://httpbin.org"

async def index_blocks(block_from: int, block_to: int):
    """Index a block range"""
    global TOTAL_TXS, TOTAL_REVERTED_TXS
    print(f"Indexing blocks from {block_from} to {block_to}")
    urls = [f"anything/{block}?expanded=true" for block in range(block_from, block_to)]
    block_responses = await up(
        urls, method="GET", base_url=THOR_URL, timeout=5, max_retries_on_timeout=2
    )

def get_contract_txs():
    best_block = 87  # get_best_block()
    loop = asyncio.new_event_loop()
    # index_from = best_block - (INDEX_DAYS * BLOCKS_PER_DAY)
    index_from = 4
    loop.run_until_complete(index_blocks(index_from, best_block))

def main():
    get_contract_txs()
    # print(f"Total transactions for VOT3 or B3TR: {TOTAL_TXS}")
    # print(f"Total transactions reverted: {TOTAL_REVERTED_TXS}")
    # print(f"Clauses to debug trace: {len(REVERTED_TXS)}")

if __name__ == "__main__":
    main()

Here is the output:

python gh-157.py 
Indexing blocks from 4 to 87
Making async requests: 100%|████████████████████████████| 83/83 [00:01<00:00, 76.20it/s]

How many requests are you trying to do? Maybe you have to modify the limits and timeouts?

RafaelWO commented 4 months ago

@claytonneal I might have fixed your issue in #197 which was part of yesterday's release 0.4.0. Please upgrade to the new version and check if your issue still persists, thanks! :slightly_smiling_face:

RafaelWO commented 3 months ago

I'm closing this ticket due to inactivity. Please open a new one (or re-open it) if you still have issues.