1

I was having some trouble using the manager. I want to have two processes accessing one list, one writing and one reading it. But the data was coming corrupted, so I tried to make an example to post here. Now, I have another problem. I'm passing a list as an argument to a function but the code doesn't work and says that I'm passing two arguments instead of one. Here is the code: import multiprocessing

def mde(dad):
    for i in range(100):
        for j in range(10):
            dad[0] = i
            dad[1] = j
def mda(dad):
    c = 0
    while c < 1001:
        print(dad)
        c += 1

if __name__ == '__main__':
    manager = multiprocessing.Manager()
    dado = manager.list([0, 0])
    print(dado)
    p1 = multiprocessing.Process(target=mde, args=dado)
    p2 = multiprocessing.Process(target=mda, args=dado)
    p1.start()
    p2.start()
    p1.join()
    p2.join()

1 Answer 1

1

Send your args as a tuple:

import multiprocessing
def mde(dad):
    for i in range(100):
        for j in range(10):
            dad[0] = i
            dad[1] = j
def mda(dad):
    c = 0
    while c < 1001:
        print(dad)
        c += 1

if __name__ == '__main__':
    manager = multiprocessing.Manager()
    dado = manager.list([0, 0])
    print(dado)
    p1 = multiprocessing.Process(target=mde, args=(dado,))
    p2 = multiprocessing.Process(target=mda, args=(dado,))
    p1.start()
    p2.start()
    p1.join()
    p2.join()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.