Skip to content

fix: Show independent tasks in the table #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2025

Conversation

mgmacias95
Copy link

Having a script with two independent event loops, only one of them is displayed in the table. This PR fixes that.

import asyncio
import threading

async def factorial(name, number):
    f = 1
    for i in range(2, number + 1):
        print(f"Task {name}: Compute factorial({number}), currently i={i}...")
        await asyncio.sleep(1)
        f *= i
    print(f"Task {name}: factorial({number}) = {f}")
    return f

async def main():
    # Schedule three calls *concurrently*:
    L = await asyncio.gather(
        factorial("A", 200),
        factorial("B", 300),
        factorial("C", 400),
    )
    print(L)

async def main2():
    await asyncio.sleep(100)


t1 = threading.Thread(target=asyncio.run, args=(main(),))
t2 = threading.Thread(target=asyncio.run, args=(main2(),))

t1.start()
t2.start()
t1.join()
t2.join()

@pablogsal pablogsal merged commit d92b520 into pablogsal:GH-91048-tasks May 3, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants