1
1
/// Main callout wrapper.
2
2
/// To use:
3
3
/// 1. Call: do ##class(isc.py.Callout).Setup() once per systems start
4
- /// 2. Call: do ##class(isc.py.Callout).Initialize() once per process
5
- /// 3. Call main method (can be called many times, context persists): write ##class(isc.py.Callout).SimpleString(code, data)
6
- /// 4. Call: do ##class(isc.py.Callout).Finalize() to free Python context
7
- /// 5. Call: write ##class(isc.py.Callout).Unload() to free callout library
4
+ /// 2. Call main method (can be called many times, context persists): write ##class(isc.py.Callout).SimpleString(code, data)
5
+ /// 3. Call: do ##class(isc.py.Callout).Finalize() to clear Python context
6
+ /// 4. Call: write ##class(isc.py.Callout).Unload() to free callout library
8
7
Class isc .py .Callout
9
8
{
10
9
@@ -22,6 +21,8 @@ Parameter SimpleStringFull As Integer = 5;
22
21
23
22
Parameter SimpleString As Integer = 6 ;
24
23
24
+ /// Get path to DLL.
25
+ /// DLL assumed to be in bin folder, unless specified otherwise
25
26
ClassMethod GetDLL () [ CodeMode = expression ]
26
27
{
27
28
$g (^isc .py .Callout , $g (^%SYS (" bindir" )) _ " iscpython." _ $select ($$$isWINDOWS:" dll" , 1 :" so" ))
@@ -38,12 +39,14 @@ ClassMethod Setup()
38
39
}
39
40
40
41
/// Init Python context. Idempotent.
42
+ /// Currently this is done automatically on a C side of things.
43
+ /// Left for debugging/dev purposes.
41
44
/// do ##class(isc.py.Callout).Initialize()
42
45
ClassMethod Initialize (debug As %Boolean = {$$$NO}) As %Integer
43
46
{
44
47
if debug {
45
- set sc = $ZF (-4 ,4 ,..#PyLibId) // unload current copy of inputlib
46
- set sc = $ZF (-4 ,8 ) // delete existing process index, if any
48
+ set sc = $ZF (-4 ,4 ,..#PyLibId) // unload current copy of inputlib
49
+ set sc = $ZF (-4 ,8 ) // delete existing process index, if any
47
50
set sc = $ZF (-4 ,7 ,..#PyLibId, ..GetDLL ()) // override system index
48
51
}
49
52
do $ZF (-6 , ..#PyLibId, ..#Initialize)
@@ -81,6 +84,7 @@ ClassMethod SimpleStringFull(code = {"import random;" _ $$$NL _ "x=random.random
81
84
82
85
/// Eval code vaiable in initialized context and
83
86
/// return value of variable str evaluation
87
+ /// TODO determine wide variable value.
84
88
/// write ##class(isc.py.Callout).SimpleString()
85
89
ClassMethod SimpleString (code As %String = {" import random;" _ $$$NL _ " x=random.random();" }, variable As %String = " x" ) As %Double
86
90
{
0 commit comments