@@ -35,11 +35,11 @@ ensure the packages [arrr](https://arrr.readthedocs.io/en/latest/) and
35
35
[ numberwang] ( https://numberwang.readthedocs.io/en/latest/ ) are installed from
36
36
PyPI (the [ Python Packaging Index] ( https://pypi.org/ ) ):
37
37
38
- ``` TOML title="Configuration via TOML"
38
+ ``` TOML title="Configuration via TOML. "
39
39
packages = [" arrr" , " numberwang" ]
40
40
```
41
41
42
- ``` JSON title="Configuration via JSON"
42
+ ``` JSON title="Configuration via JSON. "
43
43
{
44
44
"packages" : [" arrr" , " numberwang" ]
45
45
}
@@ -56,15 +56,15 @@ reference it from the tag used to specify the Python code:
56
56
57
57
If you use JSON, you can make it the value of the ` config ` attribute:
58
58
59
- ``` HTML title="JSON as the value of the config attribute"
59
+ ``` HTML title="JSON as the value of the config attribute. "
60
60
<script type =" mpy" src =" main.py" config =' {"packages":["arrr", "numberwang"]}' ></script >
61
61
```
62
62
63
63
For historical and convenience reasons we still support the inline
64
64
specification of configuration information via a _ single_ ` <py-config> ` or
65
65
` <mpy-config> ` tag in your HTML document:
66
66
67
- ``` HTML title="Inline configuration via the < ; py-config> ; tag"
67
+ ``` HTML title="Inline configuration via the < ; py-config> ; tag. "
68
68
<py-config >
69
69
{
70
70
"packages": ["arrr", "numberwang" ]
@@ -79,10 +79,10 @@ specification of configuration information via a _single_ `<py-config>` or
79
79
80
80
## Options
81
81
82
- There are four core options ([ ` interpreter ` ] ( #interpreter ) , [ ` files ` ] ( #files ) ,
83
- [ ` packages ` ] ( #packages ) , and
84
- [ ` js_modules ` ] ( #javascript-modules ) ) and an experimental flag
85
- ([ experimental_create_proxy] ( #experimental_create_proxy ) ) that can be used in
82
+ There are five core options ([ ` interpreter ` ] ( #interpreter ) , [ ` files ` ] ( #files ) ,
83
+ [ ` packages ` ] ( #packages ) , [ ` js_modules ` ] ( #javascript-modules ) and
84
+ [ ` sync_main_only ` ] ( #sync_main_only ) ) and an experimental flag
85
+ ([ ` experimental_create_proxy ` ] ( #experimental_create_proxy ) ) that can be used in
86
86
the configuration of PyScript. The user is also free to define
87
87
arbitrary additional configuration options that plugins or an app may require
88
88
for their own reasons.
@@ -100,11 +100,11 @@ a custom version of the interpreter.
100
100
101
101
The following two examples are equivalent:
102
102
103
- ``` TOML title="Specify the interpreter version in TOML"
103
+ ``` TOML title="Specify the interpreter version in TOML. "
104
104
interpreter = " 0.23.4"
105
105
```
106
106
107
- ``` JSON title="Specify the interpreter version in JSON"
107
+ ``` JSON title="Specify the interpreter version in JSON. "
108
108
{
109
109
"interpreter" : " 0.23.4"
110
110
}
@@ -113,7 +113,7 @@ interpreter = "0.23.4"
113
113
The following JSON fragment uses a fully qualified URL to point to the same
114
114
version of Pyodide as specified in the previous examples:
115
115
116
- ``` JSON title="Specify the interpreter via a fully qualified URL"
116
+ ``` JSON title="Specify the interpreter via a fully qualified URL. "
117
117
{
118
118
"interpreter" : " https://cdn.jsdelivr.net/pyodide/v0.23.4/full/pyodide.mjs"
119
119
}
@@ -127,7 +127,7 @@ destination filesystem path.
127
127
128
128
The following JSON and TOML are equivalent:
129
129
130
- ``` json title="Fetch files onto the filesystem with JSON"
130
+ ``` json title="Fetch files onto the filesystem with JSON. "
131
131
{
132
132
"files" : {
133
133
"https://example.com/data.csv" : " ./data.csv" ,
@@ -136,7 +136,7 @@ The following JSON and TOML are equivalent:
136
136
}
137
137
```
138
138
139
- ``` toml title="Fetch files onto the filesystem with TOML"
139
+ ``` toml title="Fetch files onto the filesystem with TOML. "
140
140
[files ]
141
141
"https://example.com/data.csv" = " ./data.csv"
142
142
"/code.py" = " ./subdir/code.py"
@@ -147,7 +147,7 @@ URL becomes the destination filename, in the root of the filesystem, to which
147
147
the content is copied. As a result, the ` data.csv ` entry from the previous
148
148
examples could be equivalently re-written as:
149
149
150
- ``` json title="JSON implied filename in the root directory"
150
+ ``` json title="JSON implied filename in the root directory. "
151
151
{
152
152
"files" : {
153
153
"https://example.com/data.csv" : " " ,
@@ -156,7 +156,7 @@ examples could be equivalently re-written as:
156
156
}
157
157
```
158
158
159
- ``` toml title="TOML implied filename in the root directory"
159
+ ``` toml title="TOML implied filename in the root directory. "
160
160
[files ]
161
161
"https://example.com/data.csv" = " "
162
162
... etc ...
@@ -202,7 +202,7 @@ their name is replaced with their associated value.
202
202
203
203
The following JSON and TOML are equivalent:
204
204
205
- ``` json title="Using the template language in JSON"
205
+ ``` json title="Using the template language in JSON. "
206
206
{
207
207
"files" : {
208
208
"{DOMAIN}" : " https://my-server.com" ,
@@ -218,7 +218,7 @@ The following JSON and TOML are equivalent:
218
218
}
219
219
```
220
220
221
- ``` toml title="Using the template language in TOML"
221
+ ``` toml title="Using the template language in TOML. "
222
222
[files ]
223
223
"{DOMAIN}" = " https://my-server.com"
224
224
"{PATH}" = " a/path"
@@ -287,11 +287,11 @@ to be installed onto the Python path.
287
287
288
288
The following two examples are equivalent:
289
289
290
- ``` TOML title="A packages list in TOML"
290
+ ``` TOML title="A packages list in TOML. "
291
291
packages = [" arrr" , " numberwang" , " snowballstemmer>=2.2.0" ]
292
292
```
293
293
294
- ``` JSON title="A packages list in JSON"
294
+ ``` JSON title="A packages list in JSON. "
295
295
{
296
296
"packages" : [" arrr" , " numberwang" , " snowballstemmer>=2.2.0" ]
297
297
}
@@ -338,13 +338,13 @@ To specify such modules, simply provide a list of source/module name pairs.
338
338
For example, to use the excellent [ Leaflet] ( https://leafletjs.com/ ) JavaScript
339
339
module for creating interactive maps you'd add the following lines:
340
340
341
- ``` TOML title="JavaScript main thread modules defined in TOML"
341
+ ``` TOML title="JavaScript main thread modules defined in TOML. "
342
342
[js_modules .main ]
343
343
"https://cdn.jsdelivr.net/npm/[email protected] /dist/leaflet-src.esm.js" =
" leaflet"
344
344
"https://cdn.jsdelivr.net/npm/[email protected] /dist/leaflet.css" =
" leaflet" # CSS
345
345
```
346
346
347
- ``` JSON title="JavaScript main thread modules defined in JSON"
347
+ ``` JSON title="JavaScript main thread modules defined in JSON. "
348
348
{
349
349
"js_modules" : {
350
350
"main" : {
@@ -386,12 +386,12 @@ Some JavaScript modules (such as
386
386
access to the DOM and, for efficiency reasons, can be included in the worker
387
387
context:
388
388
389
- ``` TOML title="A JavaScript worker module defined in TOML"
389
+ ``` TOML title="A JavaScript worker module defined in TOML. "
390
390
[js_modules .worker ]
391
391
"https://cdn.jsdelivr.net/npm/html-escaper" = " html_escaper"
392
392
```
393
393
394
- ``` JSON title="A JavaScript worker module defined in JSON"
394
+ ``` JSON title="A JavaScript worker module defined in JSON. "
395
395
{
396
396
"js_modules" : {
397
397
"worker" : {
@@ -404,6 +404,40 @@ context:
404
404
However, ` from pyscript.js_modules import html_escaper ` would then only work
405
405
within the context of Python code ** running on a worker** .
406
406
407
+ ### sync_main_only
408
+
409
+ Sometimes you just want to start an expensive computation on a web worker
410
+ without the need for the worker to interact with the main thread. You're simply
411
+ awaiting the result of a method exposed from a worker.
412
+
413
+ This has the advantage of not requiring the use of ` SharedArrayBuffer ` and
414
+ [ associated CORS related header configuration] ( ../workers/#http-headers ) .
415
+
416
+ If the ` sync_main_only ` flag is set, then ** interactions between the main thread
417
+ and workers are limited to one way calls from the main thread to methods
418
+ exposed by the workers** .
419
+
420
+ ``` TOML title="Setting the sync_main_only flag in TOML."
421
+ sync_main_only = true
422
+ ```
423
+
424
+ ``` JSON title="Setting the sync_main_only flag in JSON."
425
+ {
426
+ "sync_main_only" : true
427
+ }
428
+ ```
429
+
430
+ If ` sync_main_only ` is set, the following caveats apply:
431
+
432
+ * It is not possible to manipulate the DOM or do anything meaningful on the
433
+ main thread ** from a worker** . This is because Atomics cannot guarantee
434
+ sync-like locks between a worker and the main thread.
435
+ * Only a worker's ` pyscript.sync ` methods are exposed, and ** they can only be
436
+ awaited from the main thread** .
437
+ * The worker can only ` await ` main thread references one after the other, so
438
+ developer experience is degraded when one needs to interact with the
439
+ main thread.
440
+
407
441
### experimental_create_proxy
408
442
409
443
Knowing when to use the ` pyscript.ffi.create_proxy ` method when using Pyodide
0 commit comments