[Python] Multiprocessing spawn_main throwing OSError: [WinError 87] The parameter is incorrect

Discussão em 'Python' iniciado por Stack, Março 4, 2025.

  1. Stack

    Stack Membro Participativo

    I am learning distributed process on an python tutorial website : https://www.liaoxuefeng.com/wiki/00...29340191970154d52b9d484b88a7b343708fcc60000#0

    Here is the turorial code that run as a main process.

    task_master.py


    import random, time, queue
    from multiprocessing.managers import BaseManager


    task_queue = queue.Queue()
    result_queue = queue.Queue()

    class QueueManager(BaseManager):
    pass

    QueueManager.register('get_task_queue', callable=lambda:task_queue)
    QueueManager.register('get_result_queue', callable=lambda:result_queue)
    manager = QueueManager(address=('',5000), authkey=b'abc')
    manager.start()
    task = manager.get_task_queue()
    result = manager.get_result_queue()
    for i in range(10):
    n = random.randint(0,10000)
    print('Put task %d...' %n)
    task.put(n)
    print('Try get result...')
    for i in range(10):
    r = result.get(timeout = 10)
    print('Result:%s'%r)
    manager.shutdown()
    print('master exit.')


    The code is not completed, for it raises some errors that I have no idea how to deal with when I tied to run it on my computer.

    error


    D:\py>Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\Raven\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 99, in spawn_main
    new_handle = reduction.steal_handle(parent_pid, pipe_handle)
    File "C:\Users\Raven\AppData\Local\Programs\Python\Python36\lib\multiprocessing\reduction.py", line 82, in steal_handle
    _winapi.PROCESS_DUP_HANDLE, False, source_pid)
    OSError: [WinError 87] The parameter is incorrect。

    Continue reading...

Compartilhe esta Página