django save error

六眼飞鱼酱① 提交于 2019-12-11 15:10:14

问题


for *** :
   try:
       xx = A(
          a=x,
          b=y
       )
       xx.save()
   except:
     pass

here is my question: once one of the "xx" saved error, others will not save success. Does any one know why? thanks!

here is the error message

Exception
[2011-08-22 14:02:23,879: WARNING/PoolWorker-1] RuntimeError
[2011-08-22 14:02:23,879: WARNING/PoolWorker-1] :
[2011-08-22 14:02:23,879: WARNING/PoolWorker-1] 'generator ignored GeneratorExit'
[2011-08-22 14:02:23,879: WARNING/PoolWorker-1] in
[2011-08-22 14:02:23,880: WARNING/PoolWorker-1] <generator object msg_iter_page at 0x2ec28c0>
[2011-08-22 14:02:23,880: WARNING/PoolWorker-1] ignored

回答1:


You catch every exception with this statement:

except:
   pass

GeneratorExit is just an exception. This should not be caught. Please catch only the exceptions, you expect.




回答2:


You shouldn't catch GeneratorExit. If you want to catch all exceptions inherited from Exception rather then from BaseException you should change your code for:

for *** :
   try:
       xx = A(
          a=x,
          b=y
       )
       xx.save()
   except Exception:
     pass


来源:https://stackoverflow.com/questions/7143635/django-save-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!