Skip to content

Commit d2d5400

Browse files
committed
Fix module import path in WrapperDemo method; add WithoutWrapperDemo method for direct module import and execution
1 parent 3b694a8 commit d2d5400

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

demo/iris/PEX/NonProduction.cls

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ClassMethod WrapperDemo() As %Status
55
{
66

77
// Import the module
8-
set tModule = ##class(IOP.Wrapper).Import("my_script", "/irisdev/app/demo/python/non_production/", 54132)
8+
set tModule = ##class(IOP.Wrapper).Import("my_script", "/irisdev/app/demo/python/non_production", 54132)
99

1010
// Call the function
1111
set result = tModule.main()
@@ -14,4 +14,21 @@ ClassMethod WrapperDemo() As %Status
1414
write result
1515
}
1616

17+
ClassMethod WithoutWrapperDemo() As %Status
18+
{
19+
20+
// Set the Python path
21+
set sys = ##class(%SYS.Python).Import("sys")
22+
do sys."path"."append"("/irisdev/app/demo/python/non_production")
23+
24+
// Import the module directly
25+
set tModule = ##class(%SYS.Python).Import("my_script")
26+
27+
// Call the function
28+
set result = tModule.main()
29+
30+
// Print the result
31+
write result
32+
}
33+
1734
}

demo/python/non_production/my_script.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import random
23

34
def main():
45
# Get the value of the environment variable
@@ -7,6 +8,12 @@ def main():
78
# Print the value of the environment variable
89
print(f'MY_ENV_VAR: {my_env_var}')
910

11+
if random.choice([True, False]):
12+
# Simulate a condition that raises an exception
13+
print("An error occurred!")
14+
# Raise an exception to demonstrate error handling
15+
raise Exception("This is a demo exception to illustrate error handling.")
16+
1017
return "Script executed successfully!"
1118

1219

0 commit comments

Comments
 (0)