ImportError: Failed to import _strptime because the import lockis held by another thread.

Bug #947231 reported by Ferdinand
66
This bug affects 8 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Medium
OpenERP Publisher's Warranty Team

Bug Description

2012-03-05 16:05:20,044 7205 DEBUG ? openerp.cron: Database 'tl61_test_uos' wake-up! Firing multi-threaded cron job processing
2012-03-05 16:05:20,049 7205 DEBUG ? openerp.addons.base.ir.ir_cron: Cron execution thread for job `Run Event Reminder` spawned
2012-03-05 16:05:20,050 7205 WARNING ? openerp.addons.base.ir.ir_cron: Exception in cron:
Traceback (most recent call last):
  File "/srv/openerp/instances/61XA/src/server/openerp/addons/base/ir/ir_cron.py", line 254, in _run_jobs_multithread
    next_call = calendar.timegm(time.strptime(next_call, DEFAULT_SERVER_DATETIME_FORMAT))
ImportError: Failed to import _strptime because the import lockis held by another thread.
2012-03-05 16:05:20,051 7205 DEBUG ? openerp.cron: Going to sleep for 60s

is this a warning or a real error?

Tags: maintenance

Related branches

Revision history for this message
Jignesh Rathod(OpenERP) (jir-openerp) wrote :

Hello Ferdinand ,

I have checked your issue at my end with trunk as well as 6.1
but I did not face any problem regarding this issue,
So would you please elaborate more with proper steps.

Thanks and waiting for reply!

Changed in openobject-server:
status: New → Incomplete
Revision history for this message
Amit Parik (amit-parik) wrote :

Hello,

I have faced the same problem with 6.1 when cron jobs run with multi-threading.
I have faced this problem when in my database more then schedule action with same time.

I have tried this with trunk also but I don't know why I didn't face problem on trunk.
As I seen the trunk as 6.1 has same code.
    next_call = calendar.timegm(time.strptime(next_call, DEFAULT_SERVER_DATETIME_FORMAT)).

I want to say that it's hard to reproduce.That's why I have attached the screen-shot where I have faced the problem.
Here in trunk and 6.1 has a same code as well as two bug are reported foe this.

I am going to confirm this issue and assign to framework team. I would like to request with framework team, If you not able to reproduce it (as I said it's hard to reproduce) please double check it because I have faced this issue more then 3 times.

Thank you!

Revision history for this message
Amit Parik (amit-parik) wrote :
Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Low
status: Incomplete → Confirmed
Revision history for this message
Amit Parik (amit-parik) wrote :

Hello,

Today I have faced the same problem in trunk also please see attached screen-shot.

Thanks!

Revision history for this message
Amit Parik (amit-parik) wrote :
Revision history for this message
Serge (sboivin) wrote :

Solution is simple, when you see the problem, if you dont use a IDE to debug you will never see the bug because of

Try:
Finally:

(no except, so no log)

bug come from PYTHON bug READ IT : http://bugs.python.org/issue7980

Solution is

server/openerp/addons/base/ir/ir_cron.py

in function _run_jobs_multithread, need to do a dummy to strptime

+ #http://bugs.python.org/issue7980
+ datetime.strptime('2012-01-01', '%Y-%m-%d')
                # Got the lock on the job row, now spawn a thread to execute it in the transaction with the lock
                task_thread = threading.Thread(target=self._run_job, name=job['name'], args=(task_cr, job, now))

By the way use of Try, Finally without a except is NEVER a good idea ! (see def _run_job(self, cr, job, now))

Revision history for this message
Ray Carnes (rcarnes) wrote :

This is happening to me on an Ubuntu 11.10 os with 6.1.1 released.

Serge - is your fix to add:

datetime.strptime('2012-01-01', '%Y-%m-%d')

?

Does this just go above the task_thread line?

What is the impact of this error?

I am noticing it on a generic install with sample data installed in the database - no changes to any server actions via cron.

Ray.

Revision history for this message
Epsilon Bug (r7-bugs-h6) wrote :

To solve the problem, you need do a dummy call of strptime before start a thread.

#dummy call
datetime.strptime('2012-01-01', '%Y-%m-%d')
#start thread
task_thread = threading.Thread(target=self._run_job, name=job['name'], args=(task_cr, job, now))

This is a python bug, strptime dont work fine with threading, all that explain on python bug report.

The only one impact is : No more crash. the dummy call not stored in any variable, this only initialise the datetime.strptime.

Changed in openobject-server:
importance: Low → Medium
Revision history for this message
tozm (tozm) wrote :

I was getting this problem on Ubuntu 12.04 but not on Windows... so I assume this is a Linx-specific problem?

Revision history for this message
tozm (tozm) wrote :

Actually I just got it under Win 7 too (under debugger)

Can we have a comment about what the plan is to resolve this?

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

This is a well known Python issue. See http://stackoverflow.com/questions/2427240/thread-safe-equivalent-to-pythons-time-strptime for instance. The fix is well known too, as mentionned previously in the thread : calling strptime once before launching the threads is enough. This could be done e.g. in some __init__.py file which would be garanteed to be executed before threads are started.

Changed in openobject-server:
assignee: OpenERP's Framework R&D (openerp-dev-framework) → OpenERP Publisher's Warranty Team (openerp-opw)
tags: added: maintenance
Changed in openobject-server:
status: Confirmed → In Progress
Revision history for this message
Somesh Khare (somesh.khare) wrote :

Hello Serge,

Thanks for your contribution on this.

It has been fixed into the lp:~openerp-dev/openobject-server/6.1-opw-581239-skh branch,

Revision ID: <email address hidden>
Revision Number: 4296

This branch is under the review of our experts and will me merged soon into the stable.

Thanks

Changed in openobject-server:
status: In Progress → Fix Committed
Revision history for this message
Manu (manu-tiedra) wrote :

more than 2 months and still pending? :(

Revision history for this message
Xavier ALT (dex-phx) wrote :

Hi,

Fix released on server v6.1 branch with revid:

<email address hidden>

Regards,
Xavier

Changed in openobject-server:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.