2012-03-13 64 views
1

我使用python版本libtorrent将函数包装成线程并忽略严重错误

terminate called after throwing an instance of 'boost::lock_error' 
    what(): boost::lock_error 

所以,我想我会换洪流相关功能到一个单独的线程,当它崩溃,它会杀死:当我运行与许多文件较长时间洪流会话,它与一个错误崩溃只是线程(而不是整个应用程序):

from threading import Thread 

class TWrapper (Thread) : 
    # ... 
    def run(self): 
     try: 
      run_torrent_stuff() 
     except: 
      # print message 
      pass 


t = TWrapper() 
t.run() 
t.join() 
# check if all OK with t, if not - restart again 

我认为,如果库崩溃,线程会死,我会join它的主循环。但是,当libtorrent崩溃,所有的应用程序死:(

为什么错误的线程之外升级?

libtorrent就是一个例子(现实生活),问题是一般)

+0

'为什么错误在线程之外升级?' - 也许在其他线程上可能会引发异常libtorrent内部线程/池? – 2012-03-13 15:00:31

回答

2

通常,如果线程崩溃,它会导致进程崩溃,如果你想避免它在单独的进程中运行libtorrent。

+0

我尝试了'mutiprocessing.Process's类s,让我们拭目以待...... – 2012-03-13 14:56:15