@contextmanager
def emitting(exit, enter=None):
    if enter is not None:
        emit(enter)

    try:
        yield
    finally:
        emit(exit)
Context manager for emitting signals either on enter or on exit of a context.
dataset/ETHPy150Open shaunduncan/smokesignal/smokesignal.py/emitting