summaryrefslogtreecommitdiff
path: root/regtest
diff options
context:
space:
mode:
authorElliott Sales de Andrade <quantum.analyst@gmail.com>2018-10-21 21:30:04 -0400
committerAlbert Astals Cid <tsdgeos@yahoo.es>2018-11-18 09:53:40 +0000
commit98a84ba86d5b675b4cd490455c5f5d644235b5c3 (patch)
treedba1b5cefc9b4f283b32b124c1cfa5afe0965838 /regtest
parent6c427f7ecb97780ae3405be9ba6c7f0d9fe934dc (diff)
regtest: Don't use exceptions for Printer singleton.
In Python 3, exceptions must derive from the BaseException class, which Printer definitely does not do.
Diffstat (limited to 'regtest')
-rw-r--r--regtest/Printer.py26
1 files changed, 12 insertions, 14 deletions
diff --git a/regtest/Printer.py b/regtest/Printer.py
index 23ef7b3f..7da4b82d 100644
--- a/regtest/Printer.py
+++ b/regtest/Printer.py
@@ -21,13 +21,16 @@ from Config import Config
from threading import RLock
-class Printer:
- __single = None
+_instance = None
+
+class Printer:
def __init__(self):
- if Printer.__single is not None:
- raise Printer.__single
+ global _instance
+ if _instance is not None:
+ raise RuntimeError('Printer must not be instantiated more than '
+ 'once. Use the get_printer() function instead.')
self._verbose = Config().verbose
self._stream = sys.stdout
@@ -37,7 +40,7 @@ class Printer:
self._lock = RLock()
- Printer.__single = self
+ _instance = self
def _erase_current_line(self):
if not self._current_line_len:
@@ -99,13 +102,8 @@ class Printer:
with self._lock:
self._blocked -= 1
-def get_printer():
- try:
- instance = Printer()
- except Printer, i:
- instance = i
-
- return instance
-
-
+def get_printer():
+ if _instance is None:
+ Printer()
+ return _instance