Jupyte笔记本,为什么我从一开始就有1个以上的线程?

发布于 2025-02-11 15:25:44 字数 325 浏览 0 评论 0原文

我已经在互联网上搜索过,但似乎以前没人问这个问题。
我正在学习python线程。
当我在VSCDOE上的Jupyter笔记本上运行此代码时 (这是一个新文件,只有内部的代码)

import threading
print(threading.active_count()) # 6

我已经尝试过CMD和Pycharm,它们都显示 1 是主线程。

我很好奇其他5个线程来自Jupyter Notebook。
此问题仅出现在Jupyter笔记本上。
我想念什么吗?
任何提示或建议都很棒!

I have searched on the Internet, but it seems no one asked this question before.
I am learning python threading.
When I run this code on my Jupyter notebook on VScdoe
(it's a new file, and only has this code inside)

import threading
print(threading.active_count()) # 6

I have tried on cmd and pyCharm, both of them show 1 which is the main thread.

I am curious where are the other 5 threads coming from on Jupyter notebook.
And this issue only appears on Jupyter notebook.
Did I miss something?
Any tips or suggestions would be awesome!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甩你一脸翔 2025-02-18 15:25:44

其他线程由Jupyter笔记本,Ipython及其服务使用。
您可以打印他们的名称W,然后查看哪些服务使用线程

for thread in threading.enumerate(): 
    print(thread.name)

for Istance,我的Jupyter笔记本电脑不使用我的代码打印中的线程

MainThread
IOPub
Heartbeat
Control
IPythonHistorySavingThread
Thread-4
Thread-5

The other threads are used by Jupyter notebook, IPython and their services.
You can print their namew and see which services are using threads with

for thread in threading.enumerate(): 
    print(thread.name)

For istance, my Jupyter notebook which does not make use of threads in my code prints

MainThread
IOPub
Heartbeat
Control
IPythonHistorySavingThread
Thread-4
Thread-5
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文