Best way to determine whether a module is running in the main page or in a webworker?

18 views
Skip to first unread message

ben...@gmail.com

unread,
Dec 14, 2023, 11:31:14 PM12/14/23
to brython
I have some modules that I use in a webworker on one page, and in the main page on others.  Right now I import either window or self using:

try:
    from browser import window as context
except:
    from browser import self as context

and then access either as context.  But I see that brython is trying (and failing) to load /static/lib/Lib/browser/window.py from my web server once for each module doing this from a webworker, which must be slowing down my loading.

Is there a better, faster way to test whether or not code is running in a webworker?

Thanks!
Ben

Pierre Quentel

unread,
Dec 15, 2023, 5:43:05 AM12/15/23
to bry...@googlegroups.com
You can use the attribute browser.is_webworker. It was not documented so far, I have updated the documentation.

Thanks,
Pierre

Sans virus.www.avast.com

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/664db48b-bc30-42dd-bc0c-969636862fe1n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages