eric6/E5Utilities/E5MutexLocker.py

changeset 7774
9eed155411f0
child 7775
4a1db75550bd
equal deleted inserted replaced
7773:fe42bd17d4fe 7774:9eed155411f0
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2020 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a context manager locking and unlocking a mutex.
8 """
9
10 import contextlib
11
12
13 class E5MutexLocker(contextlib.AbstractContextManager):
14 """
15 Class implementing a context manager locking and unlocking a mutex.
16 """
17 def __init__(self, mutex):
18 """
19 Constructor
20
21 @param mutex reference to the mutex to be locked
22 @type QMutex or QRecursiveMutex
23 """
24 self.__mutex = mutex
25
26 def __enter__(self):
27 """
28 Special method called when entering the runtime ccontext.
29
30 @return reference to the context manager object
31 @rtype E5OverrideCursor
32 """
33 self.__mutex.lock()
34
35 return self
36
37 def __exit__(self, exc_type, exc_value, traceback):
38 """
39 Special method called when exiting the runtime ccontext.
40
41 @param exc_type type of an exception raised in the runtime context
42 @param exc_value value of an exception raised in the runtime context
43 @param traceback traceback of an exception raised in the runtime
44 context
45 @return always returns None to not suppress any exception
46 @rtype None
47 """
48 self.__mutex.unlock()
49
50 return None

eric ide

mercurial