src/eric7/EricUtilities/EricMutexLocker.py

Sat, 23 Dec 2023 15:48:12 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 23 Dec 2023 15:48:12 +0100
branch
eric7
changeset 10439
21c28b0f9e41
parent 10423
299802979277
child 10689
3ede487187f2
permissions
-rw-r--r--

Updated copyright for 2024.

# -*- coding: utf-8 -*-

# Copyright (c) 2020 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a context manager locking and unlocking a mutex.
"""

import contextlib


class EricMutexLocker(contextlib.AbstractContextManager):
    """
    Class implementing a context manager locking and unlocking a mutex.
    """

    def __init__(self, mutex):
        """
        Constructor

        @param mutex reference to the mutex to be locked
        @type QMutex or QRecursiveMutex
        """
        self.__mutex = mutex

    def __enter__(self):
        """
        Special method called when entering the runtime ccontext.

        @return reference to the context manager object
        @rtype EricOverrideCursor
        """
        self.__mutex.lock()

        return self

    def __exit__(self, exc_type, exc_value, traceback):
        """
        Special method called when exiting the runtime ccontext.

        @param exc_type type of an exception raised in the runtime context
        @type Class
        @param exc_value value of an exception raised in the runtime context
        @type Exception
        @param traceback traceback of an exception raised in the runtime
            context
        @type Traceback
        @return always returns None to not suppress any exception
        @rtype None
        """
        self.__mutex.unlock()

        return None  # __IGNORE_WARNING_M831__

eric ide

mercurial