-
Notifications
You must be signed in to change notification settings - Fork 1
Zmq freerun #129
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
Zmq freerun #129
Changes from all commits
a60e88a
8b5c653
60e0fb6
39e8068
5c4ef57
ee83053
b37b79c
4bf6723
a71cd85
eb9de9e
abada36
65858c7
0e2c75e
be6e797
0e47394
b72c7d8
bd4eb65
197fbd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |
| from datetime import UTC, datetime | ||
| from functools import partial | ||
| from logging import Logger | ||
| from typing import TYPE_CHECKING, Any, ParamSpec, Self, TypeVar | ||
| from typing import TYPE_CHECKING, Any, ParamSpec, Self, TypeVar, overload | ||
|
|
||
| from noob import Tube, init_logger | ||
| from noob.asset import AssetScope | ||
|
|
@@ -180,7 +180,20 @@ def iter(self, n: int | None = None) -> Generator[ReturnNodeType, None, None]: | |
| finally: | ||
| self.deinit() | ||
|
|
||
| @overload | ||
| def run(self, n: int) -> list[ReturnNodeType]: ... | ||
|
|
||
| @overload | ||
| def run(self, n: None) -> None: ... | ||
|
|
||
| def run(self, n: int | None = None) -> None | list[ReturnNodeType]: | ||
| """ | ||
| Run the tube infinitely or for a fixed number of iterations in a row. | ||
|
|
||
| Returns results if ``n`` is not ``None`` - | ||
| If ``n`` is ``None`` , we assume we are going to be running for a very long time, | ||
| and don't want to have an infinitely-growing collection in memory. | ||
| """ | ||
| try: | ||
| _ = self.tube.input_collection.validate_input(InputScope.process, {}) | ||
| except InputMissingError as e: | ||
|
|
@@ -540,25 +553,33 @@ def call_async_from_sync( | |
|
|
||
| result_future: asyncio.Future[_TReturn] = asyncio.Future() | ||
| work_ready = threading.Condition() | ||
| finished = False | ||
|
|
||
| # Closures because this code should never escape the containment tomb of this crime against god | ||
| async def _wrap(call_result: asyncio.Future[_TReturn], fn: Coroutine) -> None: | ||
| nonlocal finished | ||
| try: | ||
| result = await fn | ||
| call_result.set_result(result) | ||
| except Exception as e: | ||
| call_result.set_exception(e) | ||
| finally: | ||
| finished = True | ||
|
|
||
| def _done(_: ConcurrentFuture) -> None: | ||
| nonlocal finished | ||
|
|
||
| finished = True | ||
| with work_ready: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this ok to be not nonlocal? clearly it's working since tests are passing but why
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure what you mean? this is
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh sorry i was asking about
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha my b. No thats fine since we dont rebind |
||
| work_ready.notify_all() | ||
|
|
||
| future_inner = executor.submit(asyncio.run, _wrap(result_future, coro)) | ||
| future_inner.add_done_callback(_done) | ||
|
|
||
| with work_ready: | ||
| work_ready.wait() | ||
| try: | ||
| while not finished and not future_inner.done(): | ||
| with work_ready: | ||
| work_ready.wait(timeout=1) | ||
raymondwjang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| res = result_future.result() | ||
| return res | ||
| finally: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.