我正在编写一个textitor类:
from threading import *
class Editor(Thread):
{python code}
if __name__ == "__main__":
editor = Editor()
editor.start()
我希望这个编辑器线程作为守护进程运行。我该怎么做呢?我试过:
editor = Editor(daemon=True)
editor.daemon = True
self.daemon = True
问候,戴夫
就像下面的
from threading import *
class Editor(Thread):
def __init__(self, is_daemon: bool):
super(Editor, self).__init__(daemon=is_daemon)
def run(self):
print('in run')
if __name__ == "__main__":
editor = Editor(True)
print(editor.daemon)
editor.start()