Skip to content

DisposableExtensions

QuantConnect.Util.DisposableExtensions

Bases: Object

Provides extensions methods for IDisposable

dispose_safely

dispose_safely(disposable: IDisposable) -> bool
dispose_safely(
    disposable: IDisposable,
    error_handler: Callable[[Exception], Any],
) -> bool

Signature descriptions:

  • Calls IDisposable.Dispose within a try/catch and logs any errors.

  • Calls IDisposable.Dispose within a try/catch and invokes the error_handler on any errors.

Parameters:

Name Type Description Default
disposable IDisposable

The IDisposable to be disposed

required
error_handler Optional[Callable[[Exception], Any]]

Error handler delegate invoked if an exception is thrown

None

Returns:

Type Description
bool

Depends on the signature used. Case 1: [True if the object was successfully disposed, false if an error was thrown.]; Case 2: [True if the object was successfully disposed, false if an error was thrown or]