I am still not able to get a extern class set for my special system exception subroutine. See my example:
File ‘web.py’ contains
#-------------------------------- Import modules -------------------------------
import importlib
import os
import sys
#-------------------------------- Initialize data ------------------------------
msg = ‘’
syspth = ‘bsx’
#*------------------------------- Once-only processing -------------------------
while(True):
#------------------------------ Import function ‘webbs1’ ---------------------
flifnc = syspth + ‘/pgm/webbs1.py’
if not os.path.isfile(flifnc):
msg = ‘Missing function file ‘’ + flifnc + ‘’’
break
z = importlib.import_module(flifnc[0:-3].replace(’/’, ‘.’))
#------------------------------ Call function ‘webbs1’ -----------------------
msg, glb = z.webbs1(syspth)
#-----------------------------------------------------------------------------
print('Log information from -web-: ’ + glb.flplog)
break
#-------------------------------- Print message --------------------------------
if msg != ‘’:
print(msg)
#-------------------------------------------------------------------------------
File ‘webbs1.py’ contains
#=== File ‘webbs1.py’ =========== Process web base system (part 1/2) ===========
def webbs1(syspth):
#------------------------------ Import modules -------------------------------
import importlib
import os
import sys
import time
#------------------------------ Initialize data ------------------------------
glb = False
msg = ‘’
#------------------------------ Once-only processing -------------------------
swtrun = True
while(swtrun):
#---------------------------- Import web global data -----------------------
flicls = ‘bsx/pgm/cls/webglb.py’
if not os.path.isfile(flicls):
msg = ‘Missing web global data class file ‘’ + flicls + ‘’’
break
z = importlib.import_module(flicls[0:-3].replace(’/’, ‘.’))
glb = z.WebGlb()
glb.syspth = syspth
#---------------------------- Initialize log data --------------------------
flilog = glb.syspth + glb._FLILOG
indwrk = flilog.rfind(’/’)
if not os.path.exists(flilog[:indwrk]):
os.makedirs(flilog[:indwrk])
if not os.path.isfile(flilog):
open(flilog, ‘w’, encoding=‘utf-8’).close()
glb.flolog = open(flilog, ‘a’, encoding=‘utf-8’)
glb.flplog = flilog
#---------------------------- Initialize system exception handler ----------
sys.excepthook = sysexc
xxx = xxx # WRONG statement going to function ‘sysexc’
msg = ‘Successfully executed!’
swtrun = False
#---------------------------------------------------------------------------
#-----------------------------------------------------------------------------
return (msg, glb)
#-------------------------------------------------------------------------------
def sysexc( # System exception subroutine ------------------
exctpx, # …
excmsg, # …
trb # …
):
#------------------------------ Import modules -------------------------------
import traceback
#------------------------------ Create log message ---------------------------
print(‘Starting exception routine …’)
print(’-1-’)
print(exctpx)
print(’-2-’)
print(excmsg)
for pstwrk in range(len(traceback.format_tb(trb))-1 , -1, -1):
print(’-3-’)
print(traceback.format_tb(trb)[pstwrk].replace(’\n ‘, ‘:’)[1:])
print(’-4’)
print(‘Log information from -web-: … HOW to get data from global data?’)
#===============================================================================
File 'WebGlb.py’
# File ‘WebGlb.py’ ============== Web global data ==============================
class WebGlb:
#-----------------------------------------------------------------------------
def init(self):
#---------------------------- Initialize file names-------------------------
self._FLILOG = ‘/log/log.txt’
self._FLIFNC = ‘/pyx/.py’
self._FLIPKL = '/txt/.pkl’
self._FLISBR = ‘/pyx/sbr/***.py’
#---------------------------- Initialize attributes ------------------------
self.flolog = False # Web log file object
self.flplog = False # Web log file path
self.glb = False # Web global data object
# (needed for function sysexc)
self.tblsbr = { # Table of subroutines
‘websbrlog’ : ‘’,
‘websbrtxt’ : ‘’
}
#---------------------------------------------------------------------------
#-----------------------------------------------------------------------------
#===============================================================================
I am very much looking forward to your satisfactory solution!