[Kimchi-devel] [PATCH] AsyncTask: Propagate cherrypy request information to worker threads

zhshzhou at linux.vnet.ibm.com zhshzhou at linux.vnet.ibm.com
Tue Apr 1 07:55:57 UTC 2014


From: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>

cherrypy.request is a proxy for cherrypy.serving.request, and
cherrypy.serving stores the request information on the thread local
storage. When new threads created by Kimchi code, the related request
information is not propagated to the new threads. The problem is that
exception message translation code needs the Accept-Language header or
session cookie to determine which language the user speaks. If the
request information is missing, it assumes the language is English.

Usually this is not a problem because most of the threads in Kimchi just
run in background, and the exception message is written to log, so
English in log is OK. However the AsyncTask catches the exception in
thread and reports to the front-end, and this is not friendly to the
user without proper translation.

This patch propagates the request information to the new threads started
by the AsyncTask, so exception message gets translated according to the
request header or session cookie.

Signed-off-by: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>
---
 src/kimchi/asynctask.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/kimchi/asynctask.py b/src/kimchi/asynctask.py
index 8f0d96c..b54f143 100644
--- a/src/kimchi/asynctask.py
+++ b/src/kimchi/asynctask.py
@@ -37,6 +37,7 @@ class AsyncTask(object):
         self.status = 'running'
         self.message = 'OK'
         self._save_helper()
+        self._cp_request = cherrypy.serving.request
         self.thread = threading.Thread(target=self._run_helper,
                                        args=(opaque, self._status_cb))
         self.thread.setDaemon(True)
@@ -63,6 +64,7 @@ class AsyncTask(object):
             session.store('task', self.id, obj)
 
     def _run_helper(self, opaque, cb):
+        cherrypy.serving.request = self._cp_request
         try:
             self.fn(cb, opaque)
         except Exception, e:
-- 
1.8.5.3




More information about the Kimchi-devel mailing list