@@ -271,7 +271,7 @@ public PythonContext(ScriptDomainManager/*!*/ manager, IDictionary<string, objec
271
271
try {
272
272
HookAssemblyResolve ( ) ;
273
273
} catch ( System . Security . SecurityException ) {
274
- // We may not have SecurityPermissionFlag.ControlAppDomain.
274
+ // We may not have SecurityPermissionFlag.ControlAppDomain.
275
275
// If so, we will not look up sys.path for module loads
276
276
}
277
277
}
@@ -1238,7 +1238,7 @@ private void UnhookAssemblyResolve() {
1238
1238
try {
1239
1239
AppDomain . CurrentDomain . AssemblyResolve -= _resolveHolder . AssemblyResolveEvent ;
1240
1240
} catch ( System . Security . SecurityException ) {
1241
- // We may not have SecurityPermissionFlag.ControlAppDomain.
1241
+ // We may not have SecurityPermissionFlag.ControlAppDomain.
1242
1242
// If so, we will not look up sys.path for module loads
1243
1243
}
1244
1244
}
@@ -1295,6 +1295,17 @@ public override void Shutdown() {
1295
1295
}
1296
1296
#endif
1297
1297
}
1298
+
1299
+ // clean up globals from modules
1300
+ foreach ( var module in SystemStateModules . Values ) {
1301
+ if ( module is PythonModule pyModule ) {
1302
+ pyModule . Cleanup ( SharedContext ) ;
1303
+ }
1304
+ }
1305
+
1306
+ // allow finalizers to run before shutdown
1307
+ GC . Collect ( ) ;
1308
+ GC . WaitForPendingFinalizers ( ) ;
1298
1309
}
1299
1310
1300
1311
// TODO: ExceptionFormatter service
@@ -1569,7 +1580,7 @@ public override TService GetService<TService>(params object[] args) {
1569
1580
1570
1581
/// <summary>
1571
1582
/// Returns (and creates if necessary) the PythonService that is associated with this PythonContext.
1572
- ///
1583
+ ///
1573
1584
/// The PythonService is used for providing remoted convenience helpers for the DLR hosting APIs.
1574
1585
/// </summary>
1575
1586
internal Hosting . PythonService GetPythonService ( Microsoft . Scripting . Hosting . ScriptEngine engine ) {
@@ -1678,7 +1689,7 @@ private Dictionary<string, Type> CreateBuiltinTable() {
1678
1689
1679
1690
if ( Environment . OSVersion . Platform == PlatformID . Unix ) {
1680
1691
// we make our nt package show up as a posix package
1681
- // on unix platforms. Because we build on top of the
1692
+ // on unix platforms. Because we build on top of the
1682
1693
// CLI for all file operations we should be good from
1683
1694
// there, but modules that check for the presence of
1684
1695
// names (e.g. os) will do the right thing.
@@ -2529,8 +2540,8 @@ private CallSite<Func<CallSite, object, T>> MakeConvertSite<T>(ConversionResultK
2529
2540
2530
2541
/// <summary>
2531
2542
/// Invokes the specified operation on the provided arguments and returns the new resulting value.
2532
- ///
2533
- /// operation is usually a value from StandardOperators (standard CLR/DLR operator) or
2543
+ ///
2544
+ /// operation is usually a value from StandardOperators (standard CLR/DLR operator) or
2534
2545
/// OperatorStrings (a Python specific operator)
2535
2546
/// </summary>
2536
2547
internal object Operation ( PythonOperationKind operation , object self , object other ) {
@@ -2987,13 +2998,13 @@ internal CultureInfo NumericCulture {
2987
2998
/// <summary>
2988
2999
/// Sets the current command dispatcher for the Python command line. The previous dispatcher
2989
3000
/// is returned. Null can be passed to remove the current command dispatcher.
2990
- ///
3001
+ ///
2991
3002
/// The command dispatcher will be called with a delegate to be executed. The command dispatcher
2992
3003
/// should invoke the target delegate in the desired context.
2993
- ///
3004
+ ///
2994
3005
/// A common use for this is to enable running all REPL commands on the UI thread while the REPL
2995
3006
/// continues to run on a non-UI thread.
2996
- ///
3007
+ ///
2997
3008
/// The ipy.exe REPL will call into PythonContext.DispatchCommand to dispatch each execution to
2998
3009
/// the correct thread. Other REPLs can do the same to support this functionality as well.
2999
3010
/// </summary>
@@ -3094,8 +3105,8 @@ public int Compare(object x, object y) {
3094
3105
/// <summary>
3095
3106
/// Gets a function which can be used for comparing two values using the normal
3096
3107
/// Python semantics.
3097
- ///
3098
- /// If type is null then a generic comparison function is returned. If type is
3108
+ ///
3109
+ /// If type is null then a generic comparison function is returned. If type is
3099
3110
/// not null a comparison function is returned that's used for just that type.
3100
3111
/// </summary>
3101
3112
internal IComparer GetComparer ( Type type ) {
0 commit comments