Worker caveats

Abierto
#158 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
42/100
Tipo de issue
Documentación
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python

Línea de trabajo

Start with the FAQ section and review the linked SVG image demo, especially the ordering of listener registration and the inline image source. Document the listener-ordering caveat for main and worker contexts, with guidance to register bootstrap listeners ahead of time; the FAQ is done when this scenario and the recommended ordering are clear.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

I just realized, out of a one-off example in Discord, that if a worker has listeners added after some reference is created or populated with values, the synchronous dance might mislead because that reference on the main might have been already bootstrapped or triggered/resolved.

The explicit issue I am talking about is this one:

image = window.Image.new()
# if this is before, we're all good
image.onload = lambda e: document.body.append(image)
# if that is after though, setting an inline source of the image
# will resolve it before the next `.onload = ...` or even
# `.addEventListener` is attached
image.src = f'data:image/svg+xml;utf8,{svg}'

The demo in case is this one https://pyscript.com/@agiammarchi/svg-image/latest?files=main.py,index.html

I had to double-check why, once added the worker attribute, that would not work.

Due inability to hook into listeners happening on the main, I think it's worth it to document the best way to be sure a listener is triggered, either on main or worker thread, is to define listeners related to such bootstrap AOT (Ahead of Time) and not later.

This is an important detail I could see myself failing at remembering on occasions, so I think it should be part, at least, of our F.A.Q.s section.

Lenguaje dominante
Python
Estrellas
17
Forks
20
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de pyscript/docs

Todos los issues de pyscript/docs

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.