Comments (12)
The following code works for me.
from pyscript.
@nasrin1748 Yes, currentScript works fine in the main thread - itβs specifically when the using the worker
attribute that there seems to be an issue.
from pyscript.
This is awkward ... I got confused by the target
export which is supposed to work out of the box in workers too.
True that currentScript is now polluted on main only: https://github.com/pyscript/polyscript/blob/bb0ae0bc90fbe7b6671ecb8202d79194f7d3c382/esm/script-handler.js#L59-L62
This must be fixed !!!
from pyscript.
OK, I am confused ... but at least I remembered correctly:
pyscript/pyscript.core/src/plugins-helper.js
Lines 15 to 26 in 0f788fa
Will investigate and fix this soon, thanks again for the report!
from pyscript.
FYI I've fixed (or better, implemented) currentScript
as part of the polyscript logic and module.
This is guaranteed to return the right node even if invoked lazily, which is the opposite of what document.currentScript
offers, as that doesn't always guarantee the reference is the expected one.
More work needs to be done in PyScript to somehow expose that in either main or worker code, but I start believing we should always use the polyscript.currentScript
instead of monkey-patching, in an inevitable error prone way, the global document
reference. I don't think we should necessarily deprecate that, it's still part of the standard, but I think this should be a better way forward:
from pyscript import currentScript
We already normalize window
and document
, and adding this export would likely never fail expectations and it can be always available in both main and workers thanks to polyscript logic behind.
@JeffersGlass @ntoll @madhur-tandon what do you think?
edit
- the commit with currentScript
- the updated documentation around polyscript exports: https://pyscript.github.io/polyscript/#the-polyscript-module
from pyscript.
LGTM - I rather like @JeffersGlass 's suggestion of a get_current_script()
function discussed in the Tuesday call.
from pyscript.
let's please discuss only here: #1930 (reply in thread)
from pyscript.
fixed via __terminal__
from pyscript.
So finally what's going to work?
from pyscript import get_current_script
from pyscript import current_script
import pyscript
I am unable to import any of these.
from pyscript.
@nasrin1748 from polyscript import currentScript
works reliably only in workers while there is NO solution on main because a script can be async, its bootstrap is async too so other screipts might have stolen that reference already, and listeners might run any time in the future and we don't get to catch their execution out of the box and we don't want to override native DOM APIs all over.
In short, document.currentScript
is problematic on the Web on main and it's as problematic in here too so it won't get fixed on main because it cannot. The __terminal__
fixes the specific terminal case in a consistent way.
from pyscript.
@WebReflection i tried importing it in workers .Not sure where i am going wrong.
https://_12.pyscriptapps.com/broad-dust/latest/
from pyscript.
@nasrin1748 you are in a current release, we haven't released that yet.
This week we should, but if you don't want to wait for it, feel free to use the unstable channel:
https://cdn.jsdelivr.net/npm/@pyscript/core/dist/core.js
from pyscript.
Related Issues (20)
- Cannot cancel multi-cursor editing with the keyboard HOT 7
- In the code editor ctrl+enter does not create a new line below HOT 3
- `PyDom[key: int]` raises `AttributeError: 'int' object has no attribute 'indices'`
- Terminal does not show error message when using workers HOT 2
- Py Terminal issues aggregation HOT 1
- PyScript pre-resolved config URL is not consistent
- the py-editor is created repeatedly HOT 13
- MicroPython doesn't support MethodType() from "types" module! HOT 1
- MicroPython doesn't support alternative syntax to create a tuple outta comprehension HOT 1
- MicroPython should provide better error messages for missing APIs HOT 8
- Alert box issue. HOT 3
- Error message not shown. HOT 6
- terminal with worker not working HOT 2
- Saved Image not Displayed. HOT 4
- Incorrect line number in exception tracebacks HOT 18
- UnicodeEncodeError: 'ascii' codec can't encode character '\u2014' when using pyscript 2024.1.3 HOT 15
- nltk data download error HOT 1
- Unable to upload pdf file. HOT 1
- Unable to upload .mp4 file. HOT 1
- Cannot create a PyWorker from python using Pyodide HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyscript.