File tree Expand file tree Collapse file tree 1 file changed +22
-25
lines changed Expand file tree Collapse file tree 1 file changed +22
-25
lines changed Original file line number Diff line number Diff line change @@ -80,12 +80,9 @@ public void Collect(bool forceDispose = true)
80
80
if ( Instance . _finalizerTask != null
81
81
&& ! Instance . _finalizerTask . IsCompleted )
82
82
{
83
- using ( Py . GIL ( ) )
84
- {
85
- var ts = PythonEngine . BeginAllowThreads ( ) ;
86
- Instance . _finalizerTask . Wait ( ) ;
87
- PythonEngine . EndAllowThreads ( ts ) ;
88
- }
83
+ var ts = PythonEngine . BeginAllowThreads ( ) ;
84
+ Instance . _finalizerTask . Wait ( ) ;
85
+ PythonEngine . EndAllowThreads ( ts ) ;
89
86
}
90
87
else if ( forceDispose )
91
88
{
@@ -147,8 +144,11 @@ private void AddPendingCollect()
147
144
148
145
_finalizerTask = Task . Factory . StartNew ( ( ) =>
149
146
{
150
- Instance . DisposeAll ( ) ;
151
- _pending = false ;
147
+ using ( Py . GIL ( ) )
148
+ {
149
+ Instance . DisposeAll ( ) ;
150
+ _pending = false ;
151
+ }
152
152
} ) ;
153
153
}
154
154
}
@@ -169,27 +169,24 @@ private void DisposeAll()
169
169
lock ( _queueLock )
170
170
#endif
171
171
{
172
- using ( Py . GIL ( ) )
173
- {
174
172
#if FINALIZER_CHECK
175
- ValidateRefCount ( ) ;
173
+ ValidateRefCount ( ) ;
176
174
#endif
177
- IPyDisposable obj ;
178
- while ( _objQueue . TryDequeue ( out obj ) )
175
+ IPyDisposable obj ;
176
+ while ( _objQueue . TryDequeue ( out obj ) )
177
+ {
178
+ try
179
179
{
180
- try
181
- {
182
- obj . Dispose ( ) ;
183
- Runtime . CheckExceptionOccurred ( ) ;
184
- }
185
- catch ( Exception e )
180
+ obj . Dispose ( ) ;
181
+ Runtime . CheckExceptionOccurred ( ) ;
182
+ }
183
+ catch ( Exception e )
184
+ {
185
+ // We should not bother the main thread
186
+ ErrorHandler ? . Invoke ( this , new ErrorArgs ( )
186
187
{
187
- // We should not bother the main thread
188
- ErrorHandler ? . Invoke ( this , new ErrorArgs ( )
189
- {
190
- Error = e
191
- } ) ;
192
- }
188
+ Error = e
189
+ } ) ;
193
190
}
194
191
}
195
192
}
You can’t perform that action at this time.
0 commit comments