1 #!/usr/bin/env python |
1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- |
2 # -*- coding: utf-8 -*- |
3 |
3 |
4 from __future__ import absolute_import |
4 from __future__ import absolute_import |
|
5 from __future__ import print_function |
5 import traceback |
6 import traceback |
|
7 import sys |
6 |
8 |
7 from runtime.Worker import worker |
9 from runtime.Worker import worker |
8 MainWorker = worker() |
10 MainWorker = worker() |
9 |
11 |
10 from runtime.PLCObject import PLCObject |
12 from runtime.PLCObject import PLCObject # noqa # pylint: disable=wrong-import-position |
|
13 |
11 |
14 |
12 _PLCObjectSingleton = None |
15 _PLCObjectSingleton = None |
13 |
16 |
|
17 |
14 def GetPLCObjectSingleton(): |
18 def GetPLCObjectSingleton(): |
15 global _PLCObjectSingleton |
19 assert _PLCObjectSingleton is not None |
16 assert(_PLCObjectSingleton is not None) |
|
17 return _PLCObjectSingleton |
20 return _PLCObjectSingleton |
18 |
21 |
19 |
22 |
20 def LogMessageAndException(msg, exp=None): |
23 def LogMessageAndException(msg, exp=None): |
21 global _PLCObjectSingleton |
|
22 if exp is None: |
24 if exp is None: |
23 exp = sys.exc_info() |
25 exp = sys.exc_info() |
24 if _PLCObjectSingleton is not None: |
26 if _PLCObjectSingleton is not None: |
25 _PLCObjectSingleton.LogMessage(0, msg + '\n'.join(traceback.format_exception(*exp))) |
27 _PLCObjectSingleton.LogMessage(0, msg + '\n'.join(traceback.format_exception(*exp))) |
26 print(msg) |
28 print(msg) |
27 traceback.print_exception(*exp) |
29 traceback.print_exception(*exp) |
28 |
30 |
29 def CreatePLCObjectSingleton(*args): |
31 |
|
32 def CreatePLCObjectSingleton(*args, **kwargs): |
30 global _PLCObjectSingleton |
33 global _PLCObjectSingleton |
31 _PLCObjectSingleton = PLCObject(*args) |
34 _PLCObjectSingleton = PLCObject(*args, **kwargs) |