2

if a thread raises an exception, would it not release the GIL and cause deadlock?

kira
  • 31
  • 4
  • Can you elaborate a bit on this? Perhaps show some code that illustrates what the issue/scenario you're describing is. If a thread raises an exception that isn't caught, the process is terminated, for starters, so I assume you're talking about a caught exception? Thanks. – ggorlen Dec 31 '19 at 03:21
  • It is quite simple. A thread is running into exception, but not be caught. Because the thread is holding the GIL, will it release it and so that other threads can run normally? – kira Dec 31 '19 at 03:32
  • In that scenario, the exception brings the entire process down like I said, so what you're asking doesn't really make sense to me. Try it and see! – ggorlen Dec 31 '19 at 03:33
  • A MCVE would be `Thread(target=lambda: 5//0).start()`, but if you caught the exception I think the question you're posing might be more interesting. Also, if you're asking this in conjunction with a concern you have about some concrete code you're working on, adding context might be helpful. What's the motivation for asking, in other words? – ggorlen Dec 31 '19 at 03:40
  • This is just what I suddenly thought of, thanks a lot. – kira Jun 04 '20 at 06:56

0 Answers0