1
- /// Main callout wrapper.
1
+ /// Raw callout wrapper. Use isc.py.Main
2
2
/// To use:
3
3
/// 1. Call: do ##class(isc.py.Callout).Setup() once per systems start
4
4
/// 2. Call main method (can be called many times, context persists): write ##class(isc.py.Callout).SimpleString(code, data)
@@ -44,10 +44,29 @@ $g(^isc.py.Callout, $g(^%SYS("bindir")) _ "iscpython." _ $select($$$isWINDOWS:"d
44
44
/// Should be executed once per system start. Idempotent.
45
45
/// Add to ZSTART or production start.
46
46
/// write ##class(isc.py.Callout).Setup()
47
- ClassMethod Setup ()
47
+ ClassMethod Setup () As %Status
48
48
{
49
- set sc = $ZF (-4 ,6 ,..#PyLibId)
50
- set sc = $ZF (-4 ,5 ,..#PyLibId, ..GetLib ())
49
+ #dim sc As %Status = $$$OK
50
+ set file = ..GetLib ()
51
+ quit :'##class (%File ).Exists (file ) $$$ERROR($$$GeneralError, " Library file: " _ file _ " does not exist" )
52
+
53
+ try {
54
+ set result = $ZF (-4 ,6 ,..#PyLibId)
55
+ if result '=0 {
56
+ set sc = $$$ERROR($$$GeneralError, " Failed $ZF(-4, 6,..#PyLibId) call with result: " _ result _ " expected 0" )
57
+ quit
58
+ }
59
+
60
+ set result =$ZF (-4 ,5 ,..#PyLibId, file )
61
+ if result '=0 {
62
+ set sc = $$$ERROR($$$GeneralError, " Failed $ZF(-4, 5,..GetLib()) call with result: " _ result _ " expected 0" )
63
+ quit
64
+ }
65
+ } catch ex {
66
+ set sc = ex .AsStatus ()
67
+ }
68
+
69
+
51
70
quit sc
52
71
}
53
72
@@ -61,12 +80,18 @@ ClassMethod Setup()
61
80
/// In cause of problems: do ##class(isc.py.Callout).Initialize("libpython3.6m.so")
62
81
ClassMethod Initialize (file As %String = " " , debug As %Boolean = {$$$NO}) As %Integer
63
82
{
64
- if debug {
65
- set sc = $ZF (-4 ,4 ,..#PyLibId) // unload current copy of inputlib
66
- set sc = $ZF (-4 ,8 ) // delete existing process index, if any
67
- set sc = $ZF (-4 ,7 ,..#PyLibId, ..GetLib ()) // override system index
83
+ #dim sc As %Status = $$$OK
84
+ try {
85
+ if debug {
86
+ set sc = $ZF (-4 ,4 ,..#PyLibId) // unload current copy of inputlib
87
+ set sc = $ZF (-4 ,8 ) // delete existing process index, if any
88
+ set sc = $ZF (-4 ,7 ,..#PyLibId, ..GetLib ()) // override system index
89
+ }
90
+ do $ZF (-6 , ..#PyLibId, ..#Initialize, file )
91
+ } catch ex {
92
+ set sc = ex .AsStatus ()
68
93
}
69
- do $ZF (- 6 , ..#PyLibId, ..#Initialize, file )
94
+ quit sc
70
95
}
71
96
72
97
/// Test method. Get random number
@@ -169,18 +194,32 @@ ClassMethod StreamExecute() As %Status
169
194
}
170
195
171
196
/// Finalize Python. Idempotent.
172
- /// do ##class(isc.py.Callout).Finalize()
173
- ClassMethod Finalize () As %Integer
197
+ /// write ##class(isc.py.Callout).Finalize()
198
+ ClassMethod Finalize () As %Status
174
199
{
175
- do $ZF (-6 , ..#PyLibId, ..#Finalize)
200
+ try {
201
+ do $ZF (-6 , ..#PyLibId, ..#Finalize)
202
+ } catch ex {
203
+ #dim ex As %Exception.General
204
+ set sc = ex .AsStatus ()
205
+ }
206
+ quit sc
176
207
}
177
208
178
209
/// Unload library. Idempotent.
179
210
/// write ##class(isc.py.Callout).Unload()
180
- ClassMethod Unload () As %Integer
211
+ ClassMethod Unload () As %Status
181
212
{
182
- set result = $ZF (-4 , 4 , ..#PyLibId)
183
- quit result
213
+ #dim sc As %Status = $$$OK
214
+
215
+ try {
216
+ set result = $ZF (-4 , 4 , ..#PyLibId)
217
+ set :result '=0 sc = $$$ERROR($$$GeneralError, " Failed $ZF(-4, 4,..#PyLibId) call with result: " _ result _ " expected 0" )
218
+ } catch ex {
219
+ set sc = ex .AsStatus ()
220
+ }
221
+
222
+ quit sc
184
223
}
185
224
186
225
}
0 commit comments