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

《threading --- 基于线程的并行》中文文档示例代码格式化问题 #396

Open
@LeoBenChoi

Description

@LeoBenChoi

《threading --- 基于线程的并行》中文文档示例代码格式化问题

《threading --- 基于线程的并行》这个文档的示例代码,没有进行格式化

页面链接:https://docs.python.org/zh-cn/3.14/library/threading.html

页面的示例代码是这样的:

importthreadingimporttimedefcrawl(link,delay=3):print(f"crawl started for{link}")time.sleep(delay)# 阻塞 I/O (模拟网络请求)print(f"crawl ended for{link}")links= ["https://python.org","https://docs.python.org","https://peps.python.org",]# 针对每个链接启动线程threads= []forlinkinlinks:# 使用 `args` 传入位置参数并使用 `kwargs` 传入关键字参数t=threading.Thread(target=crawl,args=(link,),kwargs={"delay":2})threads.append(t)# 启动每个线程fortinthreads:t.start()# 等待所有线程结束fortinthreads:t.join()

应该格式化为

importthreadingimporttimedefcrawl(link,delay=3):print(f"crawl started for{link}")time.sleep(delay)# Blocking I/O (simulating a network request)print(f"crawl ended for{link}")links= ["https://python.org","https://docs.python.org","https://peps.python.org",]# Start threads for each linkthreads= []forlinkinlinks:# Using `args` to pass positional arguments and `kwargs` for keyword argumentst=threading.Thread(target=crawl,args=(link,),kwargs={"delay":2})threads.append(t)# Start each threadfortinthreads:t.start()# Wait for all threads to finishfortinthreads:t.join()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp