[pypy-dev] update (+patch) on embedding pypy

Roberto De Ioris roberto at unbit.it
Tue Mar 27 14:16:18 CEST 2012


Hi everyone, i have finally managed to have a pypy plugin into uWSGI via
libpypy-c.

The first step was exporting a bunch of symbols in libpypy-c:

"RPython_StartupCode", "pypy_g_ObjSpace_startup", "pypy_g_call_startup",
"pypy_g_State_startup", "pypy_g_Module_startup",
"pypy_g_pypy_module_cpyext_state_State"

pypy_g_ObjSpace_startup and pypy_g_Module_startup are not strictly
required, i have used them only for debugging some very specific areas.

Attached there is a patch for latest tip.

After that, i have defined a Py_Initialize() replacement:

http://projects.unbit.it/uwsgi/browser/plugins/python/python_plugin.c#L8

and placed a bunch of #ifdef for unsupported functions
(like PyFile_FromFile)

Finally i have built libpypy with

pypy translate.py -Ojit --shared

and the uWSGI plugin with

LDFLAGS="-L." pypy-c uwsgiconfig.py --plugin plugins/pypy core

(LDFLAGS is used as i have libpypy-c in the current dir)

Run uWSGI with the welcome app (and a bunch of processes):

uwsgi --http-socket :8080 --plugin pypy --module welcome --master
--processes 8

Incredibly the whole uwsgi api (that it is pretty complex, involving tons
of c code) works flawlessly as well as the custom wsgi.input object (the
whole upload test suite passes).

Running python threads from the WSGI app works too, but mapping python
threads to already available pthreads is a no go (all explodes, i will
investigate on that)

Importing applications as modules works normally, but importing via file
requires implementing a bunch of c-api in pypy (i will address that soon)

virtualenv, sys.argv and setting programname is not supported (no c api
available) i can get rid of this too in the next few days.

Important thing: i have tested it only on OSX

-- 
Roberto De Ioris
http://unbit.it
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libpypy_export.patch
Type: application/octet-stream
Size: 2181 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20120327/0a1dd436/attachment.obj>


More information about the pypy-dev mailing list