1
+ /// Main callout wrapper.
2
+ /// To use:
3
+ /// 1. Call: write ##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
1
8
Class isc .py .Callout
2
9
{
3
10
@@ -17,6 +24,8 @@ Parameter SimpleString As Integer = 6;
17
24
18
25
Parameter DLL As COSEXPRESSION = " $g(^isc.py.Callout, $g(^%SYS(" " bindir" " )) _ " " libhelloworld.dll" " )" ;
19
26
27
+ /// Should be executed once per system start. Idempotent.
28
+ /// Add to ZSTART or production start.
20
29
/// write ##class(isc.py.Callout).Setup()
21
30
ClassMethod Setup ()
22
31
{
@@ -25,7 +34,7 @@ ClassMethod Setup()
25
34
quit sc
26
35
}
27
36
28
- /// Init Python context
37
+ /// Init Python context. Idempotent.
29
38
/// do ##class(isc.py.Callout).Initialize()
30
39
ClassMethod Initialize (debug As %Boolean = {$$$NO}) As %Integer
31
40
{
@@ -70,7 +79,7 @@ ClassMethod SimpleStringFull(code = {"import random;" _ $$$NL _ "x=random.random
70
79
71
80
/// Eval code vaiable in initialized context and
72
81
/// return value of variable str evaluation
73
- /// w ##class(isc.py.Callout).SimpleString()
82
+ /// write ##class(isc.py.Callout).SimpleString()
74
83
ClassMethod SimpleString (code As %String = {" import random;" _ $$$NL _ " x=random.random();" }, variable As %String = " x" ) As %Double
75
84
{
76
85
set converted = $$$NO
@@ -85,15 +94,15 @@ ClassMethod SimpleString(code As %String = {"import random;" _ $$$NL _ "x=random
85
94
quit result
86
95
}
87
96
88
- /// Finalize Python
97
+ /// Finalize Python. Idempotent.
89
98
/// do ##class(isc.py.Callout).Finalize()
90
99
ClassMethod Finalize () As %Integer
91
100
{
92
101
set path = ..#DLL
93
102
do $ZF (-6 , ..#PyLibId, ..#Finalize)
94
103
}
95
104
96
- /// Unload library
105
+ /// Unload library. Idempotent.
97
106
/// write ##class(isc.py.Callout).Unload()
98
107
ClassMethod Unload () As %Integer
99
108
{
0 commit comments