@@ -39,35 +39,43 @@ public class ThreadTest {
39
39
40
40
public static string CallEchoString ( string arg ) {
41
41
IntPtr gs = PythonEngine . AcquireLock ( ) ;
42
- if ( module == null ) {
43
- module = PythonEngine . ModuleFromString ( "tt" , testmod ) ;
42
+ try {
43
+ if ( module == null ) {
44
+ module = PythonEngine . ModuleFromString ( "tt" , testmod ) ;
45
+ }
46
+ PyObject func = module . GetAttr ( "echostring" ) ;
47
+ PyString parg = new PyString ( arg ) ;
48
+ PyObject temp = func . Invoke ( parg ) ;
49
+ string result = ( string ) temp . AsManagedObject ( typeof ( String ) ) ;
50
+ func . Dispose ( ) ;
51
+ parg . Dispose ( ) ;
52
+ temp . Dispose ( ) ;
53
+ return result ;
54
+ }
55
+ finally {
56
+ PythonEngine . ReleaseLock ( gs ) ;
44
57
}
45
- PyObject func = module . GetAttr ( "echostring" ) ;
46
- PyString parg = new PyString ( arg ) ;
47
- PyObject temp = func . Invoke ( parg ) ;
48
- string result = ( string ) temp . AsManagedObject ( typeof ( String ) ) ;
49
- func . Dispose ( ) ;
50
- parg . Dispose ( ) ;
51
- temp . Dispose ( ) ;
52
- PythonEngine . ReleaseLock ( gs ) ;
53
- return result ;
54
58
}
55
59
56
60
public static string CallEchoString2 ( string arg ) {
57
61
IntPtr gs = PythonEngine . AcquireLock ( ) ;
58
- if ( module == null ) {
59
- module = PythonEngine . ModuleFromString ( "tt" , testmod ) ;
60
- }
62
+ try {
63
+ if ( module == null ) {
64
+ module = PythonEngine . ModuleFromString ( "tt" , testmod ) ;
65
+ }
61
66
62
- PyObject func = module . GetAttr ( "echostring2" ) ;
63
- PyString parg = new PyString ( arg ) ;
64
- PyObject temp = func . Invoke ( parg ) ;
65
- string result = ( string ) temp . AsManagedObject ( typeof ( String ) ) ;
66
- func . Dispose ( ) ;
67
- parg . Dispose ( ) ;
68
- temp . Dispose ( ) ;
69
- PythonEngine . ReleaseLock ( gs ) ;
70
- return result ;
67
+ PyObject func = module . GetAttr ( "echostring2" ) ;
68
+ PyString parg = new PyString ( arg ) ;
69
+ PyObject temp = func . Invoke ( parg ) ;
70
+ string result = ( string ) temp . AsManagedObject ( typeof ( String ) ) ;
71
+ func . Dispose ( ) ;
72
+ parg . Dispose ( ) ;
73
+ temp . Dispose ( ) ;
74
+ return result ;
75
+ }
76
+ finally {
77
+ PythonEngine . ReleaseLock ( gs ) ;
78
+ }
71
79
}
72
80
73
81
0 commit comments