]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
mgr: load modules in separate python sub-interpreters 14971/head
authorTim Serong <tserong@suse.com>
Fri, 12 May 2017 14:16:14 +0000 (00:16 +1000)
committerTim Serong <tserong@suse.com>
Mon, 22 May 2017 06:52:49 +0000 (16:52 +1000)
commit3e0d14912e5560583800ca442e21458a1e2ba5f7
tree3e5fc1a35a6e08182f9906fc7e3a112b4b650f29
parentf36b0d9d4053e167f59b89286cc9378e8e1563f7
mgr: load modules in separate python sub-interpreters

This provides a reasonable amount of isolation between mgr
modules.  Notably, with this change, it's possible to have more
than one mgr module use cherrypy without conflicts.

Each MgrPyModule gets its own python sub-interpreter.  The logger,
the ceph_state module and sys.path need to be set up separately
for each sub-interpreter, so all that happens in MgrPyModule's
constructor (previously this was done on the main interpreter
in PyModules::init()).

Each sub-interpreter has its own python thread state.  The main
interpreter also has a python thread state, but that is almost
unused except for during setup and teardown of the whole beast.

On top of that, an additional python thread state is necessary
for each OS thread that calls into python code (e.g. the serve()
method).

Some care needs to be taken to ensure that the right thread state
is active at the right time; note how the call to handle_pyerror()
in PyModules::init() had to be moved inside MgrPyModle::load().
PyModules should be using the main thread state, and MgrPyModule
should usually be using its sub-interpreter thread state, except
for very early in its constructor (before the sub-interpreter has
been created), and in the serve() method where another python
thread state is created to map to the separate OS thread that is
responsible for invoking this method.

The ceph_state module (PyState.cc) naturally has no idea what
context it's being run in, so uses PyThreadState_Get() when it
needs to know the python thread state.

Signed-off-by: Tim Serong <tserong@suse.com>
src/mgr/MgrPyModule.cc
src/mgr/MgrPyModule.h
src/mgr/PyModules.cc