define systemd.log_target=console when used with systemd-debug
[plcapi.git] / apache / plc.wsgi
index 840fc06..c37d369 100644 (file)
@@ -1,3 +1,4 @@
+# -*- python -*-
 #
 # Apache mod_wsgi python interface
 #
@@ -11,8 +12,6 @@ import traceback
 from PLC.Debug import log
 from PLC.API import PLCAPI
 
-api = PLCAPI()
-
 def application(environ, start_response):
     try:
         status = '200 OK'
@@ -27,6 +26,12 @@ def application(environ, start_response):
 </body></html>
 """
         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'
             ip = environ.get('REMOTE_ADDR')