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

Clean up async code #631

Merged
merged 31 commits into from
Dec 6, 2024
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fe9931a
Fix asynchronous commands
fyellin Nov 1, 2024
c733c5f
Fix lint problems and codegen problems.
fyellin Nov 1, 2024
f8a71e6
Remove assertion.
fyellin Nov 2, 2024
fbfccb7
Merge branch 'main' into async_handler
fyellin Nov 4, 2024
bebac48
_api.GPU should be the owner of its internal representation.
fyellin Nov 4, 2024
3ae7780
Thank you, ruff!
fyellin Nov 4, 2024
5fb6502
For now, use anyio
fyellin Nov 5, 2024
780ff9b
Continue to find the minimum changes
fyellin Nov 5, 2024
f831e6d
Continue to find the minimum changes
fyellin Nov 5, 2024
3b024be
Merge branch 'main' into async_handler
fyellin Nov 5, 2024
81cf2f7
Allow "await WgpuAwaitable(..)"
fyellin Nov 6, 2024
b08dc8b
Fix ruff format
fyellin Nov 6, 2024
84db283
Attempt to delay installing anyio
fyellin Nov 6, 2024
16e082e
Attempt to delay installing anyio
fyellin Nov 6, 2024
3eb1a59
Add another test.
fyellin Nov 7, 2024
466d3d9
Merge remote-tracking branch 'origin/main' into async_handler
fyellin Nov 7, 2024
54488dc
Changes requested by reviewers
fyellin Nov 7, 2024
45361ce
Change sleep to 0
fyellin Nov 14, 2024
1b903fa
Merge branch 'main' into async_handler
fyellin Nov 19, 2024
cd574c8
Small tweaks/cleanup
almarklein Nov 20, 2024
bf5862c
Implement new_array to prevent premature substruct cg
almarklein Nov 20, 2024
2f150c1
add little debug function that was very useful
almarklein Nov 20, 2024
b207bb7
fix import in test script
almarklein Nov 20, 2024
b1022ed
codegen
almarklein Nov 20, 2024
eedd8c9
Merge branch 'main' into async_handler
fyellin Nov 21, 2024
f650208
Make array store sub-refs, not sub-elements
almarklein Nov 21, 2024
c4d2388
use sniffio instead of anyio
almarklein Dec 6, 2024
9faec92
Merge branch 'main' into async_handler
almarklein Dec 6, 2024
7e6e87e
at least one sleep
almarklein Dec 6, 2024
f5acb60
fix new_array
almarklein Dec 6, 2024
6975af0
fix wheel test
almarklein Dec 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove assertion.
fyellin committed Nov 2, 2024
commit f8a71e6b1af57590d48602c797a5b246ee65cf01
15 changes: 10 additions & 5 deletions wgpu/backends/wgpu_native/_helpers.py
Original file line number Diff line number Diff line change
@@ -230,10 +230,13 @@ def to_camel_case(name):


class WgpuAwaitable:
"""An object that can be waited for, either synchronously using sync_wait() or asynchronously using await.
"""
Create an object representing the result of a wgpu call that requires a callback
to complete. The code can then call "awaitable.wait_sync()" to wait for the result
synchronously, or "await awaitable.wait_async()" to perform an asynchronous wait.

The purpose of this class is to implement the asynchronous methods in a
truly async manner, as well as to support a synchronous version of them.
The callback should call "awaitable.set_result()" when it has a result, or
"awaitable.set_error()" when it encounters an error.
"""

def __init__(self, title, callback, finalizer, poll_function=None, timeout=5.0):
@@ -255,7 +258,8 @@ def set_error(self, error):

def wait_sync(self):
if not self.poll_function:
# The result must come back without any polling.
if not self.event.is_set():
raise RuntimeError("Expected callback to have already happened")
assert self.event.is_set()
else:
maxtime = time.perf_counter() + float(self.timeout)
@@ -268,7 +272,8 @@ def wait_sync(self):

async def wait_async(self):
if not self.poll_function:
# The result must come back with the original function call.
if not self.event.is_set():
raise RuntimeError("Expected callback to have already happened")
assert self.event.is_set()
else:
maxtime = time.perf_counter() + float(self.timeout)