|
8 | 8 |
|
9 | 9 | namespace scream {
|
10 | 10 |
|
| 11 | +/* |
| 12 | + * A singleton class holding a py interpreter context |
| 13 | + * |
| 14 | + * This class is needed b/c we must ensure that a py interpreter session |
| 15 | + * is active when we call any py code. To avoid having to do that every |
| 16 | + * time we call python (directly or indirectly), users can initialize |
| 17 | + * the PySession singleton before doing any py stuff, and finalizing it |
| 18 | + * when they are done. For instance, call PySession::get().initialize() |
| 19 | + * inside an atm proc constructor, and PySession::get().finalize() inside |
| 20 | + * the destructor is a good way to ensure the py interpreter session is |
| 21 | + * active during the lifetime of the atm process. |
| 22 | + * A few notes on the class: |
| 23 | + * - it is impl-ed via singleton design |
| 24 | + * - it keeps a ref count of how many times initialize() was called, |
| 25 | + * so that it can release the py interpreter session only when the |
| 26 | + * last customer has called finalize() |
| 27 | + * - it offers convenience functions to add a path to sys.path, so that |
| 28 | + * we can later import py modules from arbitrary locations |
| 29 | + * - the safe_import method can be used to temporarily disable FPEs during |
| 30 | + * the import operation (and re-enable them right after). This is needed |
| 31 | + * for instance when importing numpy, as FPEs are generated inside the |
| 32 | + * import operation, and cannot be avoided (but are benign). |
| 33 | + */ |
| 34 | + |
11 | 35 | class PySession {
|
12 | 36 | public:
|
13 | 37 | // Avoid accidentally initializing a COPY of the session
|
|
0 commit comments