【发布时间】:2020-09-03 04:12:07
【问题描述】:
我有一个功能可以检查我想在我的 python 脚本后台持续运行的嗅探工具:
def check():
unwanted_programmes = [] # to be added to
for p in psutil.process_iter(attrs=['pid', 'name']):
for item in unwanted_programmes:
if item in str(p.info['name']).lower():
webhook_hackers(str(p.info['name'])) # send the programme to a webhook which is in another function
sys.exit()
time.sleep(1)
我希望它从头开始运行,然后是脚本的其余部分
我写过这样的代码:
if __name__ == "__main__":
check = threading.Thread(target=get_hackers())
check.start()
check.join()
threading.Thread(target=startup).start()
# startup function just does some prints and inputs before running other functions
但是,这段代码只运行一次check,然后运行startup,但我希望check 运行,然后在后台继续运行。同时,startup 只运行一次,我该怎么做?
【问题讨论】:
-
为什么不在主线程中运行检查,在while循环中,在后台线程中启动?
标签: python multithreading python-multithreading