-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compile Python as a shared library and dynamically load it at runtime #1
base: master
Are you sure you want to change the base?
Conversation
Interesting approach. Accordingly to https://github.com/kripken/emscripten/wiki/Linking I believe that brings 5-10% slowdown, but that may be worth it. The Py_Initialize error you get may be caused by not including any Python module (.py/.pyc) whatsoever in your Also one needs to make Python actually compile dlopen support (e.g. add Last it's worth noting that with 1.38.1, which defaults to WASM=1, dynamic linking is broken. |
Thanks for that feedback, I'll try your suggestions when I have time! |
I was a bit harsh with my comment about WASM, it has opened issues with dynamic loading but it works. |
hi @Beuc , did you have succes in loading wasm modules >4K since they do not support RTLD_NOW on main thread ? |
I've switched to static modules so as to use the Emterpreter, so I can't test right now. |
Btw I'm currently adding my Python tests & scripts at: |
Did some experiments today while cleaning-up my code:
Looks like that doesn't work with Chromium indeed. I asked about it at https://groups.google.com/forum/#!topic/emscripten-discuss/cE3hUV3fDSw |
exactly what i have hit on chromium 71, is it practical to load the .wasm with a worker while waiting to dlopen() it, seems your position is a "no" ? i have actually an enormous libpanda3d.js of 20MiB to download/eval after already huge libpython (3.7.2), before i can import anything. i'm quite sure wasm would be faster but i got lost in contradictory documentation and outdated samples. maybe because of difference beetween browsers ? |
I would suggest posting to the emscripten-discuss list, there are far more people there :) |
sure but the official response there is "I don't think we can point to a specific time, it depends on a lot of things, in particular on how many people help out and how much - help is always welcome and necessary" by "sample" i mean things i can work on from to help, as i already have a ffi interface for micropython-wasm ( based on @Brion work there https://github.com/brion/libffi/tree/emscripten-work ) |
I mean more people can help and give their opinion, that is a general ML (not just dev). |
ok :) and yeah maybe https://pythonclock.org/ |
I modified the code such that it build the Python shared library and compiles it to an asm.js module. I added an example that imports this shared library at runtime.
The compilation of the shared library works as does the import, but unfortunately I still get errors when running the code in production:
Summary of changes:
--enable-shared
flag to build the shared Python libraryemcc
to build a JS module from the shared library (usingSIDE_MODULE=1
to enable dynamic loading)Problems encountered:
symbol multiply defined
error. Inspecting the.a
library withllvm-nm
reveals that many symbols are defined more than once. I solved this by explicitly building the.so
library (which uses different compiler flags it seems)Py_InitializeEx
I get the following error:Python error: Py_Initialize: can't import _frozen_importlib
. I was not able to find the root cause for this (I checked in the output files in thedebug/import_error
branch for easier debugging).Any idea where the problem could be? Would be really great to get DLL loading to work, as this would allow (in my understanding) to dynamically import additional Python modules that rely on C extensions (such as numpy).