diff -r 2e38b5ec4753 -r d9175daf6522 runtime/__init__.py --- a/runtime/__init__.py Thu Aug 16 11:22:40 2018 +0200 +++ b/runtime/__init__.py Tue Aug 21 16:11:02 2018 +0200 @@ -1,28 +1,32 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# This file is part of Beremiz runtime. -# -# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD -# -# See COPYING.Runtime file for copyrights details. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. +from __future__ import absolute_import +import traceback -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. +from runtime.Worker import worker +MainWorker = worker() -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +from runtime.PLCObject import PLCObject -from __future__ import absolute_import -import os +_PLCObjectSingleton = None -from runtime.PLCObject import PLCObject, PLCprint, MainWorker -import runtime.ServicePublisher +def GetPLCObjectSingleton(): + global _PLCObjectSingleton + assert(_PLCObjectSingleton is not None) + return _PLCObjectSingleton + + +def LogMessageAndException(msg, exp=None): + global _PLCObjectSingleton + if exp is None: + exp = sys.exc_info() + if _PLCObjectSingleton is not None: + _PLCObjectSingleton.LogMessage(0, msg + '\n'.join(traceback.format_exception(*exp))) + else: + print(msg) + traceback.print_exception(*exp) + +def CreatePLCObjectSingleton(*args): + global _PLCObjectSingleton + _PLCObjectSingleton = PLCObject(*args)