Python thread exit code

后端 未结 3 649
太阳男子
太阳男子 2021-02-19 03:14

Is there a way to tell if a thread has exited normally or because of an exception?

3条回答
  •  醉话见心
    2021-02-19 04:10

    You could set some global variable to 0 if success, or non-zero if there was an exception. This is a pretty standard convention.

    However, you'll need to protect this variable with a mutex or semaphore. Or you could make sure that only one thread will ever write to it and all others would just read it.

提交回复
热议问题