Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

优化了 第三章 基于进程的并行中关于3.1节的例子的代码和解释。#97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
laixintao merged 1 commit intolaixintao:masterfromxiang162005:master
Oct 16, 2025
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletionchapter3/03_How_to_name_a_process.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,11 +22,20 @@

if __name__ == '__main__':
process_with_name = multiprocessing.Process(name='foo_process', target=foo)
process_with_name.daemon = True # 注意原代码有这一行,但是译者发现删掉这一行才能得到正确输出
process_with_name.daemon = True
process_with_default_name = multiprocessing.Process(target=foo)
process_with_name.start()
process_with_default_name.start()

"""
我们需要在最后一行加上这个join,让主进程等待foo_process进程结束才停止。
不然foo_process由于是守护进程会随着主进程的结束而立即结束。
从而来不及执行打印"Starting foo_process"和"Exiting foo_process"。

当然也可以去掉'process_with_name.daemon = True'这行代码,这也可以实现同样的效果。至于为什么,留待读者自行思考。
"""
process_with_name.join()

运行上面的代码,打开终端输入: ::

python naming_process.py
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp