mirror of
https://github.com/1j01/textual-paint.git
synced 2024-11-05 01:40:59 +03:00
Make --recode-samples handle exceptions, in an insanely complicated way
This commit is contained in:
parent
c9c58f12c6
commit
1656c64ea2
@ -182,8 +182,6 @@ This also makes it run slower.
|
||||
Often it's useful to exclude events with `textual console -x EVENT`.
|
||||
|
||||
To test file encoding, run `textual run --dev "src/textual_paint/paint.py --recode-samples"`.
|
||||
(If the program doesn't exit automatically, use `textual console -x EVENT` to check for errors.
|
||||
I'm new to asyncio in Python, and I wasn't able to get it to handle exceptions, at least not without putting a try/except inside the task, and frankly it was so obnoxiously difficult that I just had to set aside the problem for now.)
|
||||
|
||||
If there are differences in the ANSI files, you can set up a special diff like this:
|
||||
```bash
|
||||
|
@ -3390,13 +3390,25 @@ if args.recode_samples:
|
||||
app.file_path = file_path
|
||||
await app.save()
|
||||
print(f"Saved {filename}")
|
||||
app.exit()
|
||||
# asyncio.run(recode_samples())
|
||||
# have to wait for the app to be initialized
|
||||
def callback() -> None:
|
||||
# RuntimeError: asyncio.run() cannot be called from a running event loop
|
||||
# asyncio.run(recode_samples())
|
||||
asyncio.create_task(recode_samples())
|
||||
task = asyncio.create_task(recode_samples())
|
||||
app.background_tasks.add(task)
|
||||
def done_callback(future: asyncio.Future[None]) -> None:
|
||||
# print("Done callback")
|
||||
exception = future.exception()
|
||||
# print("Done callback: exception:", repr(exception))
|
||||
app.background_tasks.discard(task)
|
||||
# app.exit(1 if exception else 0, exception) # nope
|
||||
# app.exit(None, exception) # nope
|
||||
# if exception:
|
||||
# raise exception # nope
|
||||
if exception:
|
||||
def raise_exception() -> None:
|
||||
raise exception
|
||||
app.call_later(raise_exception)
|
||||
app.exit()
|
||||
task.add_done_callback(done_callback)
|
||||
app.call_later(callback)
|
||||
|
||||
if args.clear_screen:
|
||||
|
Loading…
Reference in New Issue
Block a user