Edit File: error_handler.cpython-36.pyc
3 گa& � @ s d Z ddlZddlZddlZddlZddlmZ ddlmZ ddlm Z ddlm Z ddlmZ ddlmZ dd lm Z dd lmZ ddlmZ ddlmZ eje�Zejd kr�ejgZx<ejejejejgD ]Zeje�ejkr�ej e� q�W ng ZG dd� d�Z!G dd� de!�Z"dS )zBRegisters functions to be called if an exception or signal occurs.� N)� TracebackType)�Any)�Callable)�Dict)�List)�Optional)�Type)�Union)�errors)�os�ntc @ s� e Zd ZdZedef eedd�dd�Zdd�dd �Zee e ee ee ed �dd�Z edef eedd�d d�Zdd�dd�Zdd�dd�Zdd�dd�Zeedd�dd�Zdd�dd�ZdS )�ErrorHandleraG Context manager for running code that must be cleaned up on failure. The context manager allows you to register functions that will be called when an exception (excluding SystemExit) or signal is encountered. Usage:: handler = ErrorHandler(cleanup1_func, *cleanup1_args, **cleanup1_kwargs) handler.register(cleanup2_func, *cleanup2_args, **cleanup2_kwargs) with handler: do_something() Or for one cleanup function:: with ErrorHandler(func, args, kwargs): do_something() If an exception is raised out of do_something, the cleanup functions will be called in last in first out order. Then the exception is raised. Similarly, if a signal is encountered, the cleanup functions are called followed by the previously received signal handler. Each registered cleanup function is called exactly once. If a registered function raises an exception, it is logged and the next function is called. Signals received while the registered functions are executing are deferred until they finish. .N)�func�args�kwargs�returnc O s<