File tree Expand file tree Collapse file tree 2 files changed +36
-24
lines changed Expand file tree Collapse file tree 2 files changed +36
-24
lines changed Original file line number Diff line number Diff line change @@ -13,40 +13,26 @@ public class InitializeTest
13
13
public static void LoadSpecificArgs ( )
14
14
{
15
15
var args = new [ ] { "test1" , "test2" } ;
16
- PythonEngine . Initialize ( args ) ;
17
- try
16
+ using ( new PythonEngine ( args ) )
17
+ using ( var argv = new PyList ( Runtime . Runtime . PySys_GetObject ( "argv" ) ) )
18
18
{
19
- using ( var argv = new PyList ( Runtime . Runtime . PySys_GetObject ( "argv" ) ) )
20
- {
21
- Assert . That ( argv [ 0 ] . ToString ( ) == args [ 0 ] ) ;
22
- Assert . That ( argv [ 1 ] . ToString ( ) == args [ 1 ] ) ;
23
- }
24
- }
25
- finally
26
- {
27
- PythonEngine . Shutdown ( ) ;
19
+ Assert . That ( argv [ 0 ] . ToString ( ) == args [ 0 ] ) ;
20
+ Assert . That ( argv [ 1 ] . ToString ( ) == args [ 1 ] ) ;
28
21
}
29
22
}
30
23
31
24
[ Test ]
32
25
public static void LoadDefaultArgs ( )
33
26
{
34
- PythonEngine . Initialize ( ) ;
35
- try
36
- {
37
- using ( var argv = new PyList ( Runtime . Runtime . PySys_GetObject ( "argv" ) ) )
38
- {
39
- Assert . That ( argv . Length ( ) != 0 ) ;
40
- }
41
- }
42
- finally
27
+ using ( new PythonEngine ( ) )
28
+ using ( var argv = new PyList ( Runtime . Runtime . PySys_GetObject ( "argv" ) ) )
43
29
{
44
- PythonEngine . Shutdown ( ) ;
30
+ Assert . That ( argv . Length ( ) != 0 ) ;
45
31
}
46
32
}
47
33
48
34
[ Test ]
49
- public static void Test ( )
35
+ public static void StartAndStopTwice ( )
50
36
{
51
37
PythonEngine . Initialize ( ) ;
52
38
PythonEngine . Shutdown ( ) ;
Original file line number Diff line number Diff line change @@ -10,11 +10,31 @@ namespace Python.Runtime
10
10
/// <summary>
11
11
/// This class provides the public interface of the Python runtime.
12
12
/// </summary>
13
- public class PythonEngine
13
+ public class PythonEngine : IDisposable
14
14
{
15
15
private static DelegateManager delegateManager ;
16
16
private static bool initialized ;
17
17
18
+ public PythonEngine ( )
19
+ {
20
+ Initialize ( ) ;
21
+ }
22
+
23
+ public PythonEngine ( params string [ ] args )
24
+ {
25
+ Initialize ( args ) ;
26
+ }
27
+
28
+ public PythonEngine ( IEnumerable < string > args )
29
+ {
30
+ Initialize ( args ) ;
31
+ }
32
+
33
+ public void Dispose ( )
34
+ {
35
+ Shutdown ( ) ;
36
+ }
37
+
18
38
#region Properties
19
39
20
40
public static bool IsInitialized
@@ -197,7 +217,8 @@ public static void Initialize(IEnumerable<string> args)
197
217
// when it is imported by the CLR extension module.
198
218
//====================================================================
199
219
#if PYTHON3
200
- public static IntPtr InitExt ( ) {
220
+ public static IntPtr InitExt ( )
221
+ {
201
222
#elif PYTHON2
202
223
public static void InitExt ( )
203
224
{
@@ -551,6 +572,11 @@ public static void SetArgv()
551
572
) ;
552
573
}
553
574
575
+ public static void SetArgv ( params string [ ] argv )
576
+ {
577
+ SetArgv ( argv as IEnumerable < string > ) ;
578
+ }
579
+
554
580
public static void SetArgv ( IEnumerable < string > argv )
555
581
{
556
582
using ( GIL ( ) )
You can’t perform that action at this time.
0 commit comments