mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-21 11:15:36 -05:00
Move pyodide to a web worker (#1333)
This PR adds support for optionally running pyodide in a web worker: - add a new option config.execution_thread, which can be `main` or `worker`. The default is `main` - improve the test machinery so that we run all tests twice, once for `main` and once for `worker` - add a new esbuild target which builds the code for the worker The support for workers is not complete and many features are still missing: there are 71 tests which are marked as `@skip_worker`, but we can fix them in subsequent PRs. The vast majority of tests fail because js.document is unavailable: for it to run transparently, we need the "auto-syncify" feature of synclink. Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com> Co-authored-by: Madhur Tandon <20173739+madhur-tandon@users.noreply.github.com>
This commit is contained in:
@@ -22,6 +22,7 @@ export interface AppConfig extends Record<string, any> {
|
||||
fetch?: FetchConfig[];
|
||||
plugins?: string[];
|
||||
pyscript?: PyScriptMetadata;
|
||||
execution_thread?: string; // "main" or "worker"
|
||||
}
|
||||
|
||||
export type FetchConfig = {
|
||||
@@ -43,7 +44,7 @@ export type PyScriptMetadata = {
|
||||
};
|
||||
|
||||
const allKeys = Object.entries({
|
||||
string: ['name', 'description', 'version', 'type', 'author_name', 'author_email', 'license'],
|
||||
string: ['name', 'description', 'version', 'type', 'author_name', 'author_email', 'license', 'execution_thread'],
|
||||
number: ['schema_version'],
|
||||
array: ['runtimes', 'interpreters', 'packages', 'fetch', 'plugins'],
|
||||
});
|
||||
@@ -63,6 +64,7 @@ export const defaultConfig: AppConfig = {
|
||||
packages: [],
|
||||
fetch: [],
|
||||
plugins: [],
|
||||
execution_thread: 'main',
|
||||
};
|
||||
|
||||
export function loadConfigFromElement(el: Element): AppConfig {
|
||||
@@ -237,6 +239,15 @@ function validateConfig(configText: string, configType = 'toml') {
|
||||
}
|
||||
finalConfig[item].push(eachFetchConfig);
|
||||
});
|
||||
} else if (item == 'execution_thread') {
|
||||
const value = config[item];
|
||||
if (value !== 'main' && value !== 'worker') {
|
||||
throw new UserError(
|
||||
ErrorCode.BAD_CONFIG,
|
||||
`"${value}" is not a valid value for the property "execution_thread". The only valid values are "main" and "worker"`,
|
||||
);
|
||||
}
|
||||
finalConfig[item] = value;
|
||||
} else {
|
||||
finalConfig[item] = config[item];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user