Skip to content
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

Track weight proof tasks #18896

Merged
merged 5 commits into from
Dec 11, 2024
Merged

Track weight proof tasks #18896

merged 5 commits into from
Dec 11, 2024

Conversation

almogdepaz
Copy link
Contributor

Purpose:

track weight proof segment creation tasks until closed

Current Behavior:

we cancel tasks and stop tracking them

New Behavior:

keep a list of all tasks and remove when they are done

Testing Notes:

@almogdepaz almogdepaz added full_node sync Fixed Required label for PR that categorizes merge commit message as "Fixed" for changelog labels Nov 19, 2024
@almogdepaz almogdepaz marked this pull request as ready for review November 20, 2024 16:07
@almogdepaz almogdepaz requested a review from a team as a code owner November 20, 2024 16:07
@almogdepaz almogdepaz requested a review from arvidn November 20, 2024 16:17
Copy link
Contributor

@arvidn arvidn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you also need to await any remaining tasks on shutdown

chia/full_node/full_node.py Outdated Show resolved Hide resolved
arvidn
arvidn previously approved these changes Dec 2, 2024
@arvidn
Copy link
Contributor

arvidn commented Dec 2, 2024

@altendky Is there any important distinction between checking done() and drop the reference vs. await ing the task (even when it's done)?

@altendky
Copy link
Contributor

altendky commented Dec 2, 2024

$ cat z.py
import asyncio

async def f():
    await asyncio.sleep(0.1)
    return 37

async def main():
    t = asyncio.create_task(f())
    print(await t)
    print(await t)
    c = f()
    print(await c)
    print(await c)

asyncio.run(main())
$ python z.py
37
37
37
Traceback (most recent call last):
  File "/home/altendky/z.py", line 15, in <module>
    asyncio.run(main())
  File "/home/altendky/.pyenv/versions/3.12.7/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/home/altendky/.pyenv/versions/3.12.7/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/altendky/.pyenv/versions/3.12.7/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/altendky/z.py", line 13, in main
    print(await c)
          ^^^^^^^
RuntimeError: cannot reuse already awaited coroutine

it looks like double awaiting a task is fine and you even get the result again. i added the separate case of double awaiting a coroutine object since i remembered there being an issue here and figured i'd point out the difference between the two cases.

@arvidn
Copy link
Contributor

arvidn commented Dec 2, 2024

I think of await as join()ing a thread. It seems right to always "join"

@altendky
Copy link
Contributor

altendky commented Dec 2, 2024

without having simple hard backing of the importance, yes, i would generally agree that all coroutines and tasks ought to be awaited. have to consider errors coming out of tasks and coroutines though, unlike threads.

Copy link
Contributor

@altendky altendky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A general question. Is it ok to have multiple segment tasks concurrently? Yes, we request cancellation but we don't wait for that to be completed before launching the new task. Hence the relevance of the list.

I do think that we need a systemic resolution to the general complexity of properly handling tasks. I think the solution is anyio. There are some steps that are needed before we do that. In the mean time we're basically just patching holes, adding stop gaps, etc.

chia/full_node/full_node.py Outdated Show resolved Hide resolved
chia/full_node/full_node.py Show resolved Hide resolved
chia/full_node/full_node.py Show resolved Hide resolved
@almogdepaz almogdepaz requested a review from altendky December 9, 2024 13:06
@altendky
Copy link
Contributor

altendky commented Dec 9, 2024

A general question. Is it ok to have multiple segment tasks concurrently? Yes, we request cancellation but we don't wait for that to be completed before launching the new task. Hence the relevance of the list.

Copy link
Contributor

File Coverage Missing Lines
chia/full_node/full_node.py 91.7% lines 611
Total Missing Coverage
12 lines Unknown 91%

@pmaslana pmaslana merged commit f6e08ba into main Dec 11, 2024
364 of 365 checks passed
@pmaslana pmaslana deleted the track_wp_tasks branch December 11, 2024 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
coverage-diff Fixed Required label for PR that categorizes merge commit message as "Fixed" for changelog full_node sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants