views:

456

answers:

1

The following code dies with Trace/BPT trap:

from tvdb_api import Tvdb
from threading import Thread

class GrabStuff(Thread):
    def run(self):
        t = Tvdb()

def main():
    threads = [GrabStuff() for x in range(1)]
    [x.start() for x in threads]
    [x.join() for x in threads]

if __name__ == '__main__':
    main()

The error occurs due to the Tvdb(), but I have no idea why.

I ran the code with python -m pdb thescript.py and stepped through the code, and it dies at after the following lines:

> .../threading.py(468)start()
-> _active_limbo_lock.acquire()
(Pdb) 
> .../threading.py(469)start()
-> _limbo[self] = self
(Pdb) 
> .../threading.py(470)start()
-> _active_limbo_lock.release()
(Pdb) 
> .../threading.py(471)start()
-> _start_new_thread(self.__bootstrap, ())
(Pdb) 
> .../threading.py(472)start()
-> self.__started.wait()
(Pdb) Trace/BPT trap

(I replaced the full path to threading.py with ...)

The same problem occurs with 2.6.1 and 2.5.4. The machine is running on OS X 10.6.1 Snow Leopard. The tvdb_api code can be found on github.com/dbr/tvdb_api

+3  A: 

Bad things can happen when importing modules for the first time in a thread on OS X 10.6. See, for instance, this issue. As a workaround, try looking through Tvdb and add its complete chain of imports to the main module.

Ned Deily
Strange.. Initialising Tvdb() once outside the thread (just under the import, or in `main()`) prevents the crash.. Thanks!
dbr