Fix test_async and test_stdio_handling (#1319)

Resolves pyscript#1313 and pyscript#1314. On top of pyscript#1318.

The point of these tests is to define the execution order of Tasks
that are scheduled in <py-script> tags: first all the py-script tags
are executed and their related lifecycle events. Once all of this
is done, we schedule any enqueued tasks.

To delay the execution of these tasks, we use a custom event loop for
pyExec with this defer behavior. Until schedule_deferred_tasks is called,
we defer tasks started by user code. schedule_deferred_tasks starts all 
deferred user tasks and switches to immediately scheduling any further
user tasks.
This commit is contained in:
Hood Chatham
2023-03-30 14:38:51 -07:00
committed by GitHub
parent b61e8435d1
commit e9122bca9d
7 changed files with 84 additions and 19 deletions

View File

@@ -35,8 +35,9 @@ type PATHInterface = {
type PyScriptPyModule = ProxyMarked & {
_set_version_info(ver: string): void;
uses_top_level_await(code: string): boolean;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_run_pyscript(code: string, display_target_id?: string): { result: any };
_install_pyscript_loop(): void;
_schedule_deferred_tasks(): void;
};
/*
@@ -128,6 +129,7 @@ export class RemoteInterpreter extends Object {
this.globals = Synclink.proxy(this.interface.globals as PyProxyDict);
logger.info('importing pyscript');
this.pyscript_py = Synclink.proxy(this.interface.pyimport('pyscript')) as PyProxy & typeof this.pyscript_py;
this.pyscript_py._install_pyscript_loop();
if (config.packages) {
logger.info('Found packages in configuration to install. Loading micropip...');