[IMP] attempt to dump uid performing operation along with thread stacks
authorOlivier Dony <odo@openerp.com>
Fri, 16 Mar 2012 11:12:18 +0000 (12:12 +0100)
committerOlivier Dony <odo@openerp.com>
Fri, 16 Mar 2012 11:12:18 +0000 (12:12 +0100)
bzr revid: odo@openerp.com-20120316111218-o963t7xm4r4honoy

openerp-server
openerp/netsvc.py
openerp/service/web_services.py

index f574ebb..12b6962 100755 (executable)
@@ -165,11 +165,16 @@ def dumpstacks(sig, frame):
     """ Signal handler: dump a stack trace for each existing thread."""
     # code from http://stackoverflow.com/questions/132058/getting-stack-trace-from-a-running-python-application#answer-2569696
     # modified for python 2.5 compatibility
-    thread_map = dict(threading._active, **threading._limbo)
-    id2name = dict([(threadId, thread.getName()) for threadId, thread in thread_map.items()])
+    threads_info = dict([(th.ident, {'name': th.name,
+                                    'uid': getattr(th,'uid','n/a')})
+                                for th in threading.enumerate()])
     code = []
     for threadId, stack in sys._current_frames().items():
-        code.append("\n# Thread: %s(%d)" % (id2name.get(threadId,'n/a'), threadId))
+        thread_info = threads_info.get(threadId)
+        code.append("\n# Thread: %s (id:%s) (uid:%s)" % \
+                    (thread_info and thread_info['name'] or 'n/a',
+                     threadId,
+                     thread_info and thread_info['uid'] or 'n/a'))
         for filename, lineno, name, line in traceback.extract_stack(stack):
             code.append('File: "%s", line %d, in %s' % (filename, lineno, name))
             if line:
index 0051fe6..506c1e4 100644 (file)
@@ -357,6 +357,8 @@ def dispatch_rpc(service_name, method, params):
             if rpc_request and rpc_response_flag:
                 log(rpc_request,logging.DEBUG,'%s.%s'%(service_name,method), replace_request_password(params))
 
+        threading.current_thread().uid = None
+        threading.current_thread().dbname = None
         result = ExportService.getService(service_name).dispatch(method, params)
 
         if rpc_request_flag or rpc_response_flag:
index a7136e2..46beaec 100644 (file)
@@ -561,6 +561,7 @@ class objects_proxy(netsvc.ExportService):
 
     def dispatch(self, method, params):
         (db, uid, passwd ) = params[0:3]
+        threading.current_thread().uid = uid
         params = params[3:]
         if method == 'obj_list':
             raise NameError("obj_list has been discontinued via RPC as of 6.0, please query ir.model directly!")
@@ -594,6 +595,7 @@ class wizard(netsvc.ExportService):
 
     def dispatch(self, method, params):
         (db, uid, passwd ) = params[0:3]
+        threading.current_thread().uid = uid
         params = params[3:]
         if method not in ['execute','create']:
             raise KeyError("Method not supported %s" % method)
@@ -645,6 +647,7 @@ class report_spool(netsvc.ExportService):
 
     def dispatch(self, method, params):
         (db, uid, passwd ) = params[0:3]
+        threading.current_thread().uid = uid
         params = params[3:]
         if method not in ['report', 'report_get', 'render_report']:
             raise KeyError("Method not supported %s" % method)