- else:
- api.environ = environ
- content_type = 'text/xml'
- ip = environ.get('REMOTE_ADDR')
- port = environ.get('REMOTE_PORT')
- output = api.handle((ip,port),environ.get('wsgi.input').read())
- # Shut down database connection, otherwise up to MaxClients DB
- # connections will remain open.
- api.db.close()
+ else:
+ # Thomas Dreibholz <dreibh@simula.no>
+ # Note that this function is called within multiple threads!
+ # "api" MUST be a local variable instead of a global one.
+ # Otherwise, this causes concurrent accesses to the same
+ # object within different threads!
+ api = PLCAPI()
+ api.environ = environ
+ content_type = 'text/xml; charset=utf-8'
+ ip = environ.get('REMOTE_ADDR')
+ port = environ.get('REMOTE_PORT')
+ output = api.handle((ip,port), environ.get('wsgi.input').read())
+# uncomment for debug
+# try:
+# with open("/tmp/dbgplc.log", "a") as f:
+# print(f"{ip=} {port=}\n"
+# f"{output=}",
+# file=f)
+# except Exception as exc:
+# pass
+ # Shut down database connection, otherwise up to MaxClients DB
+ # connections will remain open.
+ api.db.close()
+ except Exception as err:
+ status = '500 Internal Server Error'
+ content_type = 'text/html; charset=utf-8'
+ output = 'Internal Server Error'
+ logger.exception("INTERNAL ERROR !!")