Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1006 (closed defect: worksforme)

Opened 11 years ago

Last modified 9 years ago

misusing hub interface crashes TurboGears on shutdown

Reported by: max Owned by: anonymous
Priority: normal Milestone: 1.x
Component: SQLObject Version: 0.9a6
Severity: normal Keywords: sqlobject
Cc:

Description

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

Change History

comment:1 Changed 11 years ago by max

  • Keywords scheduler removed
  • Severity changed from major to normal
  • Summary changed from scheduled tasks that use SQLObject crash Python to misusing hub interface crashes TurboGears

Actually, the problem is unreleated to scheduler.

It is caused by missing hub.end() statement at the end of the block. Of course, it should crash the app server anyway though may be this ticket should go to sqlobject's bug tracker.

comment:2 Changed 11 years ago by max

  • Summary changed from misusing hub interface crashes TurboGears to misusing hub interface crashes TurboGears on shutdown

comment:3 Changed 11 years ago by jorge.vargas

  • Milestone set to 1.0

we need a sqlobject only probe of this and then post it to their tracker.

comment:4 Changed 11 years ago by jorge.vargas

  • Component changed from TurboGears to SQLObject

comment:5 Changed 11 years ago by alberto

  • Milestone changed from 1.0 to 1.1

comment:6 Changed 10 years ago by alberto

  • Milestone changed from 1.1 to __unclassified__

Batch moved into unclassified from 1.1 to properly track progress on the later

comment:7 Changed 9 years ago by jorge.vargas

  • Milestone changed from __unclassified__ to 1.x

comment:8 Changed 9 years ago by chrisz

  • Status changed from new to closed
  • Resolution set to worksforme

I can confirm that adding try: ... finally: hub.end() to delete_expired, this works in TG 1.0.8. I think the error message before was not that bad and we can close this; our focus is now on SQLAlchemy anway.

Note: See TracTickets for help on using tickets.