Hàng đợi đa xử lý của Python so với trình quản lý

Gọi

Value at beginning: 0
Array at beginning: [0.0, 100.0, 200.0]
Value at end: 144
Array at end: [134.0, 237.0, 339.0]
end main
0 để nói với chương trình rằng nó nên đợi quá trình này hoàn tất trước khi tiếp tục với phần còn lại của mã

from multiprocessing import Process
import os

def square_numbers[]:
    for i in range[1000]:
        result = i * i


if __name__ == "__main__":        
    processes = []
    num_processes = os.cpu_count[]
    # number of CPUs on the machine. Usually a good choise for the number of processes

    # create processes and asign a function for each process
    for i in range[num_processes]:
        process = Process[target=square_numbers]
        processes.append[process]

    # start all processes
    for process in processes:
        process.start[]

    # wait for all processes to finish
    # block the main programm until these processes are finished
    for process in processes:
        process.join[]

Chia sẻ dữ liệu giữa các tiến trình¶

Vì các quy trình không nằm trong cùng một không gian bộ nhớ nên chúng không có quyền truy cập vào cùng một dữ liệu [công khai]. Vì vậy, chúng cần các đối tượng bộ nhớ dùng chung đặc biệt để chia sẻ dữ liệu

Dữ liệu có thể được lưu trữ trong biến bộ nhớ dùng chung bằng cách sử dụng

Value at beginning: 0
Array at beginning: [0.0, 100.0, 200.0]
Value at end: 144
Array at end: [134.0, 237.0, 339.0]
end main
1 hoặc
Value at beginning: 0
Array at beginning: [0.0, 100.0, 200.0]
Value at end: 144
Array at end: [134.0, 237.0, 339.0]
end main
2

  • Value at beginning: 0
    Array at beginning: [0.0, 100.0, 200.0]
    Value at end: 144
    Array at end: [134.0, 237.0, 339.0]
    end main
    
    3. Tạo một đối tượng
    Value at beginning: 0
    Array at beginning: [0.0, 100.0, 200.0]
    Value at end: 144
    Array at end: [134.0, 237.0, 339.0]
    end main
    
    4 kiểu
    Value at beginning: 0
    Array at beginning: [0.0, 100.0, 200.0]
    Value at end: 144
    Array at end: [134.0, 237.0, 339.0]
    end main
    
    5. Truy cập giá trị bằng
    Value at beginning: 0
    Array at beginning: [0.0, 100.0, 200.0]
    Value at end: 144
    Array at end: [134.0, 237.0, 339.0]
    end main
    
    6
  • Value at beginning: 0
    Array at beginning: [0.0, 100.0, 200.0]
    Value at end: 144
    Array at end: [134.0, 237.0, 339.0]
    end main
    
    7. Tạo một mảng
    Value at beginning: 0
    Array at beginning: [0.0, 100.0, 200.0]
    Value at end: 144
    Array at end: [134.0, 237.0, 339.0]
    end main
    
    4 với các phần tử kiểu
    Value at beginning: 0
    Array at beginning: [0.0, 100.0, 200.0]
    Value at end: 144
    Array at end: [134.0, 237.0, 339.0]
    end main
    
    5. Truy cập các giá trị với
    from multiprocessing import Process
    import os
    
    def square_numbers[]:
        for i in range[1000]:
            result = i * i
    
    
    if __name__ == "__main__":        
        processes = []
        num_processes = os.cpu_count[]
        # number of CPUs on the machine. Usually a good choise for the number of processes
    
        # create processes and asign a function for each process
        for i in range[num_processes]:
            process = Process[target=square_numbers]
            processes.append[process]
    
        # start all processes
        for process in processes:
            process.start[]
    
        # wait for all processes to finish
        # block the main programm until these processes are finished
        for process in processes:
            process.join[]
    
    10

Nhiệm vụ. Tạo hai quy trình, mỗi quy trình phải có quyền truy cập vào một biến được chia sẻ và sửa đổi nó [trong trường hợp này chỉ tăng nó lặp lại 1 trong 100 lần]. Tạo hai quy trình khác chia sẻ một mảng và sửa đổi [tăng] tất cả các phần tử trong mảng

from multiprocessing import Process
import os

def square_numbers[]:
    for i in range[1000]:
        result = i * i


if __name__ == "__main__":        
    processes = []
    num_processes = os.cpu_count[]
    # number of CPUs on the machine. Usually a good choise for the number of processes

    # create processes and asign a function for each process
    for i in range[num_processes]:
        process = Process[target=square_numbers]
        processes.append[process]

    # start all processes
    for process in processes:
        process.start[]

    # wait for all processes to finish
    # block the main programm until these processes are finished
    for process in processes:
        process.join[]
2

Value at beginning: 0
Array at beginning: [0.0, 100.0, 200.0]
Value at end: 144
Array at end: [134.0, 237.0, 339.0]
end main

Cách sử dụng
from multiprocessing import Process
import os

def square_numbers[]:
    for i in range[1000]:
        result = i * i


if __name__ == "__main__":        
    processes = []
    num_processes = os.cpu_count[]
    # number of CPUs on the machine. Usually a good choise for the number of processes

    # create processes and asign a function for each process
    for i in range[num_processes]:
        process = Process[target=square_numbers]
        processes.append[process]

    # start all processes
    for process in processes:
        process.start[]

    # wait for all processes to finish
    # block the main programm until these processes are finished
    for process in processes:
        process.join[]
23¶

Lưu ý rằng trong ví dụ trên, 2 quy trình sẽ tăng giá trị được chia sẻ lên 1 trong 100 lần. Điều này dẫn đến tổng số 200 hoạt động. Nhưng tại sao giá trị cuối cùng không phải là 200?

Điều kiện của cuộc đua¶

Một điều kiện cuộc đua đã xảy ra ở đây. Tình trạng dồn đuổi xảy ra khi hai hoặc nhiều tiến trình hoặc luồng có thể truy cập dữ liệu được chia sẻ và chúng cố gắng thay đổi dữ liệu đó cùng một lúc. Trong ví dụ của chúng tôi, hai quy trình phải đọc giá trị được chia sẻ, tăng giá trị đó lên 1 và ghi lại giá trị đó vào biến được chia sẻ. Nếu điều này xảy ra đồng thời, hai quá trình sẽ đọc cùng một giá trị, tăng giá trị đó lên và ghi lại giá trị đó. Do đó, cả hai quy trình đều ghi cùng một giá trị tăng lên vào đối tượng được chia sẻ và giá trị không tăng thêm 2. Xem https. //www. kỹ sư trăn. com/learn/advancedpython16_threading/ để được giải thích chi tiết về điều kiện chủng tộc

Tránh các điều kiện cuộc đua với
from multiprocessing import Process
import os

def square_numbers[]:
    for i in range[1000]:
        result = i * i


if __name__ == "__main__":        
    processes = []
    num_processes = os.cpu_count[]
    # number of CPUs on the machine. Usually a good choise for the number of processes

    # create processes and asign a function for each process
    for i in range[num_processes]:
        process = Process[target=square_numbers]
        processes.append[process]

    # start all processes
    for process in processes:
        process.start[]

    # wait for all processes to finish
    # block the main programm until these processes are finished
    for process in processes:
        process.join[]
23¶

Khóa [còn được gọi là mutex] là một cơ chế đồng bộ hóa để thực thi các giới hạn đối với quyền truy cập vào tài nguyên trong môi trường có nhiều quy trình/luồng thực thi. Khóa có hai trạng thái. bị khóa và mở khóa. Nếu trạng thái bị khóa, nó không cho phép các quy trình/luồng đồng thời khác vào phần mã này cho đến khi trạng thái được mở khóa trở lại

Hai chức năng quan trọng. -

from multiprocessing import Process
import os

def square_numbers[]:
    for i in range[1000]:
        result = i * i


if __name__ == "__main__":        
    processes = []
    num_processes = os.cpu_count[]
    # number of CPUs on the machine. Usually a good choise for the number of processes

    # create processes and asign a function for each process
    for i in range[num_processes]:
        process = Process[target=square_numbers]
        processes.append[process]

    # start all processes
    for process in processes:
        process.start[]

    # wait for all processes to finish
    # block the main programm until these processes are finished
    for process in processes:
        process.join[]
13. Điều này sẽ khóa trạng thái và chặn -
from multiprocessing import Process
import os

def square_numbers[]:
    for i in range[1000]:
        result = i * i


if __name__ == "__main__":        
    processes = []
    num_processes = os.cpu_count[]
    # number of CPUs on the machine. Usually a good choise for the number of processes

    # create processes and asign a function for each process
    for i in range[num_processes]:
        process = Process[target=square_numbers]
        processes.append[process]

    # start all processes
    for process in processes:
        process.start[]

    # wait for all processes to finish
    # block the main programm until these processes are finished
    for process in processes:
        process.join[]
14. Điều này sẽ mở khóa trạng thái một lần nữa

Quan trọng. Bạn phải luôn giải phóng lại khối sau khi có được nó

Trong ví dụ của chúng tôi, phần mã quan trọng nơi biến được chia sẻ được đọc và tăng hiện đã bị khóa. Điều này ngăn quá trình thứ hai sửa đổi đối tượng được chia sẻ cùng một lúc. Không có nhiều thay đổi trong mã của chúng tôi. Tất cả các thay đổi mới được nhận xét trong mã bên dưới

from multiprocessing import Process
import os

def square_numbers[]:
    for i in range[1000]:
        result = i * i


if __name__ == "__main__":        
    processes = []
    num_processes = os.cpu_count[]
    # number of CPUs on the machine. Usually a good choise for the number of processes

    # create processes and asign a function for each process
    for i in range[num_processes]:
        process = Process[target=square_numbers]
        processes.append[process]

    # start all processes
    for process in processes:
        process.start[]

    # wait for all processes to finish
    # block the main programm until these processes are finished
    for process in processes:
        process.join[]
1

from multiprocessing import Process
import os

def square_numbers[]:
    for i in range[1000]:
        result = i * i


if __name__ == "__main__":        
    processes = []
    num_processes = os.cpu_count[]
    # number of CPUs on the machine. Usually a good choise for the number of processes

    # create processes and asign a function for each process
    for i in range[num_processes]:
        process = Process[target=square_numbers]
        processes.append[process]

    # start all processes
    for process in processes:
        process.start[]

    # wait for all processes to finish
    # block the main programm until these processes are finished
    for process in processes:
        process.join[]
9

Sử dụng khóa làm trình quản lý ngữ cảnh¶

Sau

from multiprocessing import Process
import os

def square_numbers[]:
    for i in range[1000]:
        result = i * i


if __name__ == "__main__":        
    processes = []
    num_processes = os.cpu_count[]
    # number of CPUs on the machine. Usually a good choise for the number of processes

    # create processes and asign a function for each process
    for i in range[num_processes]:
        process = Process[target=square_numbers]
        processes.append[process]

    # start all processes
    for process in processes:
        process.start[]

    # wait for all processes to finish
    # block the main programm until these processes are finished
    for process in processes:
        process.join[]
13, bạn đừng bao giờ quên gọi cho
from multiprocessing import Process
import os

def square_numbers[]:
    for i in range[1000]:
        result = i * i


if __name__ == "__main__":        
    processes = []
    num_processes = os.cpu_count[]
    # number of CPUs on the machine. Usually a good choise for the number of processes

    # create processes and asign a function for each process
    for i in range[num_processes]:
        process = Process[target=square_numbers]
        processes.append[process]

    # start all processes
    for process in processes:
        process.start[]

    # wait for all processes to finish
    # block the main programm until these processes are finished
    for process in processes:
        process.join[]
14 để mở khóa mã. Bạn cũng có thể sử dụng khóa làm trình quản lý bối cảnh, khóa này sẽ khóa và mở khóa mã của bạn một cách an toàn. Nên sử dụng khóa theo cách này

Value at beginning: 0
Array at beginning: [0.0, 100.0, 200.0]
Value at end: 144
Array at end: [134.0, 237.0, 339.0]
end main
2

Sử dụng hàng đợi trong Python¶

Dữ liệu cũng có thể được chia sẻ giữa các quy trình với Hàng đợi. Hàng đợi có thể được sử dụng để trao đổi dữ liệu an toàn luồng/an toàn quy trình và xử lý dữ liệu cả trong môi trường đa luồng và đa xử lý, điều đó có nghĩa là bạn có thể tránh phải sử dụng bất kỳ nguyên tắc đồng bộ hóa nào như khóa

Hàng đợi¶

Hàng đợi là một cấu trúc dữ liệu tuyến tính tuân theo nguyên tắc Nhập trước xuất trước [FIFO]. Một ví dụ điển hình là một hàng khách đang xếp hàng chờ đợi, trong đó khách hàng đến trước được phục vụ trước.

Value at beginning: 0
Array at beginning: [0.0, 100.0, 200.0]
Value at end: 144
Array at end: [134.0, 237.0, 339.0]
end main
3

Value at beginning: 0
Array at beginning: [0.0, 100.0, 200.0]
Value at end: 144
Array at end: [134.0, 237.0, 339.0]
end main
4

Sử dụng hàng đợi trong đa xử lý¶

Các hoạt động với một hàng đợi là quá trình an toàn. Hàng đợi đa xử lý thực hiện tất cả các phương thức của hàng đợi. Hàng đợi ngoại trừ

from multiprocessing import Process
import os

def square_numbers[]:
    for i in range[1000]:
        result = i * i


if __name__ == "__main__":        
    processes = []
    num_processes = os.cpu_count[]
    # number of CPUs on the machine. Usually a good choise for the number of processes

    # create processes and asign a function for each process
    for i in range[num_processes]:
        process = Process[target=square_numbers]
        processes.append[process]

    # start all processes
    for process in processes:
        process.start[]

    # wait for all processes to finish
    # block the main programm until these processes are finished
    for process in processes:
        process.join[]
17 và
from multiprocessing import Process
import os

def square_numbers[]:
    for i in range[1000]:
        result = i * i


if __name__ == "__main__":        
    processes = []
    num_processes = os.cpu_count[]
    # number of CPUs on the machine. Usually a good choise for the number of processes

    # create processes and asign a function for each process
    for i in range[num_processes]:
        process = Process[target=square_numbers]
        processes.append[process]

    # start all processes
    for process in processes:
        process.start[]

    # wait for all processes to finish
    # block the main programm until these processes are finished
    for process in processes:
        process.join[]
18. Các phương pháp quan trọng là

  • from multiprocessing import Process
    import os
    
    def square_numbers[]:
        for i in range[1000]:
            result = i * i
    
    
    if __name__ == "__main__":        
        processes = []
        num_processes = os.cpu_count[]
        # number of CPUs on the machine. Usually a good choise for the number of processes
    
        # create processes and asign a function for each process
        for i in range[num_processes]:
            process = Process[target=square_numbers]
            processes.append[process]
    
        # start all processes
        for process in processes:
            process.start[]
    
        # wait for all processes to finish
        # block the main programm until these processes are finished
        for process in processes:
            process.join[]
    
    19. Xóa và trả lại mục đầu tiên. Theo mặc định, nó chặn cho đến khi có mặt hàng
  • from multiprocessing import Process
    import os
    
    def square_numbers[]:
        for i in range[1000]:
            result = i * i
    
    
    if __name__ == "__main__":        
        processes = []
        num_processes = os.cpu_count[]
        # number of CPUs on the machine. Usually a good choise for the number of processes
    
        # create processes and asign a function for each process
        for i in range[num_processes]:
            process = Process[target=square_numbers]
            processes.append[process]
    
        # start all processes
        for process in processes:
            process.start[]
    
        # wait for all processes to finish
        # block the main programm until these processes are finished
        for process in processes:
            process.join[]
    
    90. Đặt phần tử ở cuối hàng đợi. Theo mặc định, nó sẽ chặn cho đến khi có một vị trí miễn phí
  • from multiprocessing import Process
    import os
    
    def square_numbers[]:
        for i in range[1000]:
            result = i * i
    
    
    if __name__ == "__main__":        
        processes = []
        num_processes = os.cpu_count[]
        # number of CPUs on the machine. Usually a good choise for the number of processes
    
        # create processes and asign a function for each process
        for i in range[num_processes]:
            process = Process[target=square_numbers]
            processes.append[process]
    
        # start all processes
        for process in processes:
            process.start[]
    
        # wait for all processes to finish
        # block the main programm until these processes are finished
        for process in processes:
            process.join[]
    
    91. Trả về True nếu hàng đợi rỗng
  • from multiprocessing import Process
    import os
    
    def square_numbers[]:
        for i in range[1000]:
            result = i * i
    
    
    if __name__ == "__main__":        
        processes = []
        num_processes = os.cpu_count[]
        # number of CPUs on the machine. Usually a good choise for the number of processes
    
        # create processes and asign a function for each process
        for i in range[num_processes]:
            process = Process[target=square_numbers]
            processes.append[process]
    
        # start all processes
        for process in processes:
            process.start[]
    
        # wait for all processes to finish
        # block the main programm until these processes are finished
        for process in processes:
            process.join[]
    
    92. Cho biết rằng quy trình hiện tại sẽ không đưa thêm dữ liệu vào hàng đợi này

Value at beginning: 0
Array at beginning: [0.0, 100.0, 200.0]
Value at end: 144
Array at end: [134.0, 237.0, 339.0]
end main
1

Value at beginning: 0
Array at beginning: [0.0, 100.0, 200.0]
Value at end: 144
Array at end: [134.0, 237.0, 339.0]
end main
2

Nhóm quy trình¶

Một đối tượng nhóm quy trình kiểm soát một nhóm các quy trình công nhân mà các công việc có thể được gửi tới. Nó hỗ trợ các kết quả không đồng bộ với thời gian chờ và gọi lại và có triển khai bản đồ song song. Nó có thể tự động quản lý các bộ xử lý có sẵn và chia dữ liệu thành các phần nhỏ hơn mà sau đó có thể được xử lý song song bởi các quy trình khác nhau. Xem https. // tài liệu. con trăn. tổ chức/3. 7/thư viện/đa xử lý. html#đa xử lý. pool cho tất cả các phương pháp có thể. Các phương pháp quan trọng là

  • from multiprocessing import Process
    import os
    
    def square_numbers[]:
        for i in range[1000]:
            result = i * i
    
    
    if __name__ == "__main__":        
        processes = []
        num_processes = os.cpu_count[]
        # number of CPUs on the machine. Usually a good choise for the number of processes
    
        # create processes and asign a function for each process
        for i in range[num_processes]:
            process = Process[target=square_numbers]
            processes.append[process]
    
        # start all processes
        for process in processes:
            process.start[]
    
        # wait for all processes to finish
        # block the main programm until these processes are finished
        for process in processes:
            process.join[]
    
    93. Phương pháp này cắt iterable thành một số khối mà nó gửi đến nhóm quy trình dưới dạng các tác vụ riêng biệt. Kích thước [gần đúng] của các khối này có thể được chỉ định bằng cách đặt kích thước khối thành một số nguyên dương. Nó chặn cho đến khi kết quả sẵn sàng
  • from multiprocessing import Process
    import os
    
    def square_numbers[]:
        for i in range[1000]:
            result = i * i
    
    
    if __name__ == "__main__":        
        processes = []
        num_processes = os.cpu_count[]
        # number of CPUs on the machine. Usually a good choise for the number of processes
    
        # create processes and asign a function for each process
        for i in range[num_processes]:
            process = Process[target=square_numbers]
            processes.append[process]
    
        # start all processes
        for process in processes:
            process.start[]
    
        # wait for all processes to finish
        # block the main programm until these processes are finished
        for process in processes:
            process.join[]
    
    94. Ngăn chặn bất kỳ nhiệm vụ nào khác được gửi đến nhóm. Khi tất cả các tác vụ đã được hoàn thành, các quy trình công nhân sẽ thoát
  • from multiprocessing import Process
    import os
    
    def square_numbers[]:
        for i in range[1000]:
            result = i * i
    
    
    if __name__ == "__main__":        
        processes = []
        num_processes = os.cpu_count[]
        # number of CPUs on the machine. Usually a good choise for the number of processes
    
        # create processes and asign a function for each process
        for i in range[num_processes]:
            process = Process[target=square_numbers]
            processes.append[process]
    
        # start all processes
        for process in processes:
            process.start[]
    
        # wait for all processes to finish
        # block the main programm until these processes are finished
        for process in processes:
            process.join[]
    
    18. Chờ các worker process thoát ra. Người ta phải gọi
    from multiprocessing import Process
    import os
    
    def square_numbers[]:
        for i in range[1000]:
            result = i * i
    
    
    if __name__ == "__main__":        
        processes = []
        num_processes = os.cpu_count[]
        # number of CPUs on the machine. Usually a good choise for the number of processes
    
        # create processes and asign a function for each process
        for i in range[num_processes]:
            process = Process[target=square_numbers]
            processes.append[process]
    
        # start all processes
        for process in processes:
            process.start[]
    
        # wait for all processes to finish
        # block the main programm until these processes are finished
        for process in processes:
            process.join[]
    
    94 hoặc
    from multiprocessing import Process
    import os
    
    def square_numbers[]:
        for i in range[1000]:
            result = i * i
    
    
    if __name__ == "__main__":        
        processes = []
        num_processes = os.cpu_count[]
        # number of CPUs on the machine. Usually a good choise for the number of processes
    
        # create processes and asign a function for each process
        for i in range[num_processes]:
            process = Process[target=square_numbers]
            processes.append[process]
    
        # start all processes
        for process in processes:
            process.start[]
    
        # wait for all processes to finish
        # block the main programm until these processes are finished
        for process in processes:
            process.join[]
    
    97 trước khi sử dụng
    from multiprocessing import Process
    import os
    
    def square_numbers[]:
        for i in range[1000]:
            result = i * i
    
    
    if __name__ == "__main__":        
        processes = []
        num_processes = os.cpu_count[]
        # number of CPUs on the machine. Usually a good choise for the number of processes
    
        # create processes and asign a function for each process
        for i in range[num_processes]:
            process = Process[target=square_numbers]
            processes.append[process]
    
        # start all processes
        for process in processes:
            process.start[]
    
        # wait for all processes to finish
        # block the main programm until these processes are finished
        for process in processes:
            process.join[]
    
    18
  • from multiprocessing import Process
    import os
    
    def square_numbers[]:
        for i in range[1000]:
            result = i * i
    
    
    if __name__ == "__main__":        
        processes = []
        num_processes = os.cpu_count[]
        # number of CPUs on the machine. Usually a good choise for the number of processes
    
        # create processes and asign a function for each process
        for i in range[num_processes]:
            process = Process[target=square_numbers]
            processes.append[process]
    
        # start all processes
        for process in processes:
            process.start[]
    
        # wait for all processes to finish
        # block the main programm until these processes are finished
        for process in processes:
            process.join[]
    
    99. Gọi func với các đối số args. Nó chặn cho đến khi kết quả sẵn sàng. func chỉ được thực hiện trong MỘT trong số các công nhân của nhóm

Ghi chú. Ngoài ra còn có các biến thể không đồng bộ

Value at beginning: 0
Array at beginning: [0.0, 100.0, 200.0]
Value at end: 144
Array at end: [134.0, 237.0, 339.0]
end main
20 và
Value at beginning: 0
Array at beginning: [0.0, 100.0, 200.0]
Value at end: 144
Array at end: [134.0, 237.0, 339.0]
end main
21 sẽ không chặn. Họ có thể thực hiện các cuộc gọi lại khi kết quả đã sẵn sàng

Trình quản lý đa xử lý Python là gì?

Trình quản lý đa xử lý cung cấp cách tạo các đối tượng Python tập trung có thể được chia sẻ an toàn giữa các quy trình . Trình quản lý cung cấp cách tạo dữ liệu có thể được chia sẻ giữa các quy trình khác nhau, bao gồm chia sẻ qua mạng giữa các quy trình chạy trên các máy khác nhau.

Đa xử lý có phải là một ý tưởng hay trong Python không?

Một giải pháp tuyệt vời là sử dụng đa xử lý, thay vì đa luồng , trong đó công việc được phân chia giữa các quy trình riêng biệt, cho phép hệ điều hành quản lý quyền truy cập vào các tài nguyên được chia sẻ. Điều này cũng xoay quanh một trong những gót chân Achilles khét tiếng trong Python. Khóa phiên dịch viên toàn cầu [còn gọi là theGIL].

Hàng đợi đa xử lý của Python là gì?

Đa xử lý. Hàng đợi cung cấp hàng đợi FIFO nhập trước, xuất trước, nghĩa là các mục được truy xuất từ ​​hàng đợi theo thứ tự chúng được thêm vào . Các mục đầu tiên được thêm vào hàng đợi sẽ là các mục đầu tiên được lấy. Điều này trái ngược với các loại hàng đợi khác như hàng đợi vào sau, ra trước và ưu tiên.

Quá trình xếp hàng Python có an toàn không?

Hàng đợi là chuỗi và xử lý an toàn . Điều này có nghĩa là các quy trình có thể nhận [] và đặt [] các mục từ và vào hàng đợi đồng thời mà không sợ điều kiện chạy đua. Bạn có thể tìm hiểu thêm về cách sử dụng hàng đợi với nhiều quy trình trong hướng dẫn. Hàng đợi đa xử lý trong Python.

Chủ Đề