Skip to content

Commit 6ea90f7

Browse files
committed
EAMxx: add inline documentation for the PySession singleton class
1 parent 511f8d0 commit 6ea90f7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

components/eamxx/src/share/eamxx_pysession.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,30 @@
88

99
namespace scream {
1010

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+
1135
class PySession {
1236
public:
1337
// Avoid accidentally initializing a COPY of the session

0 commit comments

Comments
 (0)