Merge lp:~vaab/openobject-server/fix-ircron-utf8-error2 into lp:openobject-server/6.1

Proposed by Valentin Lab
Status: Needs review
Proposed branch: lp:~vaab/openobject-server/fix-ircron-utf8-error2
Merge into: lp:openobject-server/6.1
Diff against target: 18 lines (+2/-2)
1 file modified
openerp/addons/base/ir/ir_cron.py (+2/-2)
To merge this branch: bzr merge lp:~vaab/openobject-server/fix-ircron-utf8-error2
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+104750@code.launchpad.net

Description of the change

job['name'] can be quite long and not very system friendly (unicode, spaces, and other characters).

The unicode part is translated in threading module thanks to "str(name)", which fails on non-ASCII characters. See the linked bug report.

It happens that I use the thread name in my logging facility, and having very long thread name is not very convenient. And conversion towards unicode is done back in the logging facility. So explicit "utf-8" encoding seems bad.

So it seems to make sense to me to use a full ASCII, small, and unique identifier as the threadname here.

Any comments ?

To post a comment you must log in.

Unmerged revisions

4160. By Valentin Lab

[FIX] ir_cron should encode the unicode job name.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/addons/base/ir/ir_cron.py'
2--- openerp/addons/base/ir/ir_cron.py 2012-02-02 09:21:05 +0000
3+++ openerp/addons/base/ir/ir_cron.py 2012-05-04 14:43:20 +0000
4@@ -234,12 +234,12 @@
5 task_cr.close()
6
7 # Got the lock on the job row, now spawn a thread to execute it in the transaction with the lock
8- task_thread = threading.Thread(target=self._run_job, name=job['name'], args=(task_cr, job, now))
9+ task_thread = threading.Thread(target=self._run_job, name="ir_cron-%d" % (job['id'], ), args=(task_cr, job, now))
10 # force non-daemon task threads (the runner thread must be daemon, and this property is inherited by default)
11 task_thread.setDaemon(False)
12 openerp.cron.take_thread_slot()
13 task_thread.start()
14- _logger.debug('Cron execution thread for job `%s` spawned', job['name'])
15+ _logger.debug('Cron execution thread for job `%s` spawned (thread-id: %s)', job['name'], task_thread.name)
16
17 # Find next earliest job ignoring currently processed jobs (by this and other cron threads)
18 find_next_time_query = """SELECT min(nextcall) AS min_next_call