eric6/E5Utilities/E5MutexLocker.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

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

eric ide

mercurial