线程在不结束的情况下运行,这会导致asyncio.run(v2_plus()。init())不运行类

发布于 2025-01-22 21:00:55 字数 841 浏览 5 评论 0原文

因此,我有一个名为main.py的Python脚本,该脚本在开始时从同一目录中的文件中导入一个名为sub.py的文件。在sub.py中,它运行了一个线程,该线程检查调试工具是否启动此代码

threading.Thread(target=self.blockDebuggers).start()
        for t in [self.listCheck, self.inVirtualenv, self.onCheck, self.specsCheck, self.dllCheck, self.procCheck]:
            x = threading.Thread(target=t)
            self.processes.append(x)
        for thread in self.processes:
            thread.start()
        for process in self.processes:
            process.join()

,一旦脚本完成了它的工作允许main.py在main的末尾运行。 (v2_plus()。init()),它似乎挂在上面。在Visual Studio中徘徊在Asyncio.run上,提到当在同一线程中运行循环时如何运行它。我不需要sub.py中的脚本来继续运行。有没有办法停止以前的线程允许asyncio.run在main.py中工作?

这使我很长一段时间以asyncio.run(v2_plus()。init())运行,但一旦达到这一点,它就会冻结。我知道这是一个在sub.py中发生的循环,将sub.py中的代码替换为简单的print('testing')一遍又一遍地吐出单词测试。

so I have a python script called main.py which on start imports a class from a file in the same directory called sub.py. in sub.py it runs a thread that checks for debugging tools it starts it with this code

threading.Thread(target=self.blockDebuggers).start()
        for t in [self.listCheck, self.inVirtualenv, self.onCheck, self.specsCheck, self.dllCheck, self.procCheck]:
            x = threading.Thread(target=t)
            self.processes.append(x)
        for thread in self.processes:
            thread.start()
        for process in self.processes:
            process.join()

once that script is finished with what its doing it allows main.py to run at the end of main.py I have asyncio.run(V2_Plus().init()) which it seems to hang at. Hovering over asyncio.run in Visual Studio mentions how it cannot be run when theres a loop running in the same thread. I don't need the script in sub.py to keep running. Is there a way to stop the previous thread to allow asyncio.run to work in main.py?

This had me stuck for a long time as all the code before asyncio.run(V2_Plus().init()) runs but once it hits that point it just freezes. I know its a loop happening in sub.py as replacing the code in sub.py to just a simple print('testing') spits out the word testing over and over in console.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文