@@ -35,11 +35,11 @@ ensure the packages [arrr](https://arrr.readthedocs.io/en/latest/) and
3535[ numberwang] ( https://numberwang.readthedocs.io/en/latest/ ) are installed from
3636PyPI (the [ Python Packaging Index] ( https://pypi.org/ ) ):
3737
38- ``` TOML title="Configuration via TOML"
38+ ``` TOML title="Configuration via TOML. "
3939packages = [" arrr" , " numberwang" ]
4040```
4141
42- ``` JSON title="Configuration via JSON"
42+ ``` JSON title="Configuration via JSON. "
4343{
4444 "packages" : [" arrr" , " numberwang" ]
4545}
@@ -56,15 +56,15 @@ reference it from the tag used to specify the Python code:
5656
5757If you use JSON, you can make it the value of the ` config ` attribute:
5858
59- ``` HTML title="JSON as the value of the config attribute"
59+ ``` HTML title="JSON as the value of the config attribute. "
6060<script type =" mpy" src =" main.py" config =' {"packages":["arrr", "numberwang"]}' ></script >
6161```
6262
6363For historical and convenience reasons we still support the inline
6464specification of configuration information via a _ single_ ` <py-config> ` or
6565` <mpy-config> ` tag in your HTML document:
6666
67- ``` HTML title="Inline configuration via the < ; py-config> ; tag"
67+ ``` HTML title="Inline configuration via the < ; py-config> ; tag. "
6868<py-config >
6969{
7070 "packages": ["arrr", "numberwang" ]
@@ -79,10 +79,10 @@ specification of configuration information via a _single_ `<py-config>` or
7979
8080## Options
8181
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
8686the configuration of PyScript. The user is also free to define
8787arbitrary additional configuration options that plugins or an app may require
8888for their own reasons.
@@ -100,11 +100,11 @@ a custom version of the interpreter.
100100
101101The following two examples are equivalent:
102102
103- ``` TOML title="Specify the interpreter version in TOML"
103+ ``` TOML title="Specify the interpreter version in TOML. "
104104interpreter = " 0.23.4"
105105```
106106
107- ``` JSON title="Specify the interpreter version in JSON"
107+ ``` JSON title="Specify the interpreter version in JSON. "
108108{
109109 "interpreter" : " 0.23.4"
110110}
@@ -113,7 +113,7 @@ interpreter = "0.23.4"
113113The following JSON fragment uses a fully qualified URL to point to the same
114114version of Pyodide as specified in the previous examples:
115115
116- ``` JSON title="Specify the interpreter via a fully qualified URL"
116+ ``` JSON title="Specify the interpreter via a fully qualified URL. "
117117{
118118 "interpreter" : " https://cdn.jsdelivr.net/pyodide/v0.23.4/full/pyodide.mjs"
119119}
@@ -127,7 +127,7 @@ destination filesystem path.
127127
128128The following JSON and TOML are equivalent:
129129
130- ``` json title="Fetch files onto the filesystem with JSON"
130+ ``` json title="Fetch files onto the filesystem with JSON. "
131131{
132132 "files" : {
133133 "https://example.com/data.csv" : " ./data.csv" ,
@@ -136,7 +136,7 @@ The following JSON and TOML are equivalent:
136136}
137137```
138138
139- ``` toml title="Fetch files onto the filesystem with TOML"
139+ ``` toml title="Fetch files onto the filesystem with TOML. "
140140[files ]
141141"https://example.com/data.csv" = " ./data.csv"
142142"/code.py" = " ./subdir/code.py"
@@ -147,7 +147,7 @@ URL becomes the destination filename, in the root of the filesystem, to which
147147the content is copied. As a result, the ` data.csv ` entry from the previous
148148examples could be equivalently re-written as:
149149
150- ``` json title="JSON implied filename in the root directory"
150+ ``` json title="JSON implied filename in the root directory. "
151151{
152152 "files" : {
153153 "https://example.com/data.csv" : " " ,
@@ -156,7 +156,7 @@ examples could be equivalently re-written as:
156156}
157157```
158158
159- ``` toml title="TOML implied filename in the root directory"
159+ ``` toml title="TOML implied filename in the root directory. "
160160[files ]
161161"https://example.com/data.csv" = " "
162162... etc ...
@@ -202,7 +202,7 @@ their name is replaced with their associated value.
202202
203203The following JSON and TOML are equivalent:
204204
205- ``` json title="Using the template language in JSON"
205+ ``` json title="Using the template language in JSON. "
206206{
207207 "files" : {
208208 "{DOMAIN}" : " https://my-server.com" ,
@@ -218,7 +218,7 @@ The following JSON and TOML are equivalent:
218218}
219219```
220220
221- ``` toml title="Using the template language in TOML"
221+ ``` toml title="Using the template language in TOML. "
222222[files ]
223223"{DOMAIN}" = " https://my-server.com"
224224"{PATH}" = " a/path"
@@ -287,11 +287,11 @@ to be installed onto the Python path.
287287
288288The following two examples are equivalent:
289289
290- ``` TOML title="A packages list in TOML"
290+ ``` TOML title="A packages list in TOML. "
291291packages = [" arrr" , " numberwang" , " snowballstemmer>=2.2.0" ]
292292```
293293
294- ``` JSON title="A packages list in JSON"
294+ ``` JSON title="A packages list in JSON. "
295295{
296296 "packages" : [" arrr" , " numberwang" , " snowballstemmer>=2.2.0" ]
297297}
@@ -338,13 +338,13 @@ To specify such modules, simply provide a list of source/module name pairs.
338338For example, to use the excellent [ Leaflet] ( https://leafletjs.com/ ) JavaScript
339339module for creating interactive maps you'd add the following lines:
340340
341- ``` TOML title="JavaScript main thread modules defined in TOML"
341+ ``` TOML title="JavaScript main thread modules defined in TOML. "
342342[js_modules .main ]
343343"https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet-src.esm.js" = " leaflet"
344344"https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.css" = " leaflet" # CSS
345345```
346346
347- ``` JSON title="JavaScript main thread modules defined in JSON"
347+ ``` JSON title="JavaScript main thread modules defined in JSON. "
348348{
349349 "js_modules" : {
350350 "main" : {
@@ -386,12 +386,12 @@ Some JavaScript modules (such as
386386access to the DOM and, for efficiency reasons, can be included in the worker
387387context:
388388
389- ``` TOML title="A JavaScript worker module defined in TOML"
389+ ``` TOML title="A JavaScript worker module defined in TOML. "
390390[js_modules .worker ]
391391"https://cdn.jsdelivr.net/npm/html-escaper" = " html_escaper"
392392```
393393
394- ``` JSON title="A JavaScript worker module defined in JSON"
394+ ``` JSON title="A JavaScript worker module defined in JSON. "
395395{
396396 "js_modules" : {
397397 "worker" : {
@@ -404,6 +404,40 @@ context:
404404However, ` from pyscript.js_modules import html_escaper ` would then only work
405405within the context of Python code ** running on a worker** .
406406
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+
407441### experimental_create_proxy
408442
409443Knowing when to use the ` pyscript.ffi.create_proxy ` method when using Pyodide
0 commit comments