-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to Atoti Python API 0.9.2 (#289)
- Loading branch information
Showing
11 changed files
with
542 additions
and
380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import asyncio | ||
from urllib.parse import urlparse | ||
|
||
from . import Config, start_app | ||
|
||
with start_app(config=Config()) as session: | ||
port = urlparse(session.url) or 80 | ||
print(f"Session listening on port {port}") # noqa: T201 | ||
session.wait() | ||
|
||
async def main() -> None: | ||
async with start_app(config=Config()) as session: | ||
port = urlparse(session.url).port or 80 | ||
print(f"Session listening on port {port}") # noqa: T201 | ||
await asyncio.to_thread(session.wait) | ||
|
||
|
||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
from collections.abc import Callable, Generator | ||
from contextlib import contextmanager | ||
import asyncio | ||
from collections.abc import AsyncGenerator, Awaitable, Callable | ||
from contextlib import asynccontextmanager | ||
from datetime import timedelta | ||
from threading import Event, Thread | ||
|
||
|
||
@contextmanager | ||
def run_periodically( | ||
callback: Callable[[], None], /, *, daemon: bool | None = None, period: timedelta | ||
) -> Generator[None, None, None]: | ||
@asynccontextmanager | ||
async def run_periodically( | ||
callback: Callable[[], Awaitable[None]], | ||
/, | ||
*, | ||
period: timedelta, | ||
) -> AsyncGenerator[None]: | ||
period_in_seconds = period.total_seconds() | ||
stopped = Event() | ||
stopped = asyncio.Event() | ||
|
||
def loop() -> None: | ||
while not stopped.wait(period_in_seconds): | ||
callback() | ||
async def loop() -> None: | ||
while not stopped.is_set(): | ||
await callback() | ||
await asyncio.sleep(period_in_seconds) | ||
|
||
Thread(target=loop, daemon=daemon).start() | ||
task = asyncio.create_task(loop()) | ||
|
||
yield | ||
|
||
stopped.set() | ||
try: | ||
yield | ||
finally: | ||
stopped.set() | ||
await task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.