#1006: scheduled tasks that use SQLObject crash Python
------------------------+---------------------------------------------------
Reporter: max | Owner: anonymous
Type: defect | Status: new
Priority: normal | Milestone:
Component: TurboGears | Version: 0.9a6
Severity: major | Keywords: scheduler sqlobject
------------------------+---------------------------------------------------
If I create a task (using new TG scheduler) that access my db model it
crashes interpreter on restart or shutdown. Crash doesn't happen unless
hub is used. It happens for both 'sequentional' and 'threaded' task
execution mode.
When used with SQLite it gives a hint: the problem is most probably some
threading/concurrency bug. SQLlite complains:
{{{
Exception pysqlite2.dbapi2.ProgrammingError: 'SQLite objects created in a
thread can only be used in that same thread.The object was created in
thread id 412 and this is thread id 2068' in <bound method
Transaction.__del__ of <sqlobject.dbconnection.Transaction object at
0x016B7590>> ignored
}}}
Behaviour observed on WinXP SP2 using MySQLdb and SQLite, Python 2.4.
Example code, controllers.py:
{{{
def test_task():
log.info("test_task")
for i in range(5):
T(name='i%d'%i, age=i, expiry=datetime.now())
T.delete_expired()
log.info("test_task finished")
def schedule_interval_tasks():
import turbogears.scheduler
task = turbogears.scheduler.add_interval_task(
initialdelay=6, interval=10,
taskname='test',
action=test_task)
log.info("Added %s task to scheduler", task.name)
}}}
Code from model.py:
{{{
class T(SQLObject):
name = StringCol()
age = IntCol()
expiry = DateTimeCol(notNull=True)
@classmethod
def delete_expired(cls):
now = datetime.now()
hub.begin()
try:
for sk in cls.select(cls.q.expiry<now):
sk.destroySelf()
hub.commit()
except:
hub.rollback()
raise
return n
}}}
--
Ticket URL: <http://trac.turbogears.org/turbogears/ticket/1006>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears Tickets" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears-tickets
-~----------~----~----~----~------~----~------~--~---