Is there a problem with inheriting from threading.Thread without actually starting the thread?

后端 未结 1 411
闹比i
闹比i 2021-01-27 13:52

I\'ve created a Python class which inherits from threading.Thread, instances of which may not actually be run as a new thread (because the start() meth

相关标签:
1条回答
  • 2021-01-27 14:33

    In my view a slightly cleaner design would be to not inherit your class from threading.Thread, but keep its run method as-is.

    Now:

    • if you don't need threading, you can continue to use your class as you do currently;
    • if you do need threading, create a new Thread object, setting the target= constructor argument to your object's run method.
    0 讨论(0)
提交回复
热议问题