Commit 98a84ba8 authored by Elliott Sales de Andrade's avatar Elliott Sales de Andrade Committed by Albert Astals Cid
Browse files

regtest: Don't use exceptions for Printer singleton.

In Python 3, exceptions must derive from the BaseException class, which
Printer definitely does not do.
parent 6c427f7e
......@@ -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():
instance = Printer()
except Printer, i:
instance = i
return instance
def get_printer():
if _instance is None:
return _instance
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment