umgefahren
umgefahren

Reputation: 165

Python & Multiprocessing

import multiprocessing

def main(a):
    while True:
        print(a)

p = multiprocessing.process(target=main(1))
p0 = multiprocessing.process(target=main(2))
p.start()
p0.start()

If you run the code it just prints:

1
1
1
1
1
1
1
1

It actullay should output something like this

1
2
1
1
2
2
2
1
2
1
2

How do I fix this: I'm doing research since this morning. Please send help.

Upvotes: 0

Views: 57

Answers (1)

BpY
BpY

Reputation: 433

Does this meet your requirements?

from multiprocessing import Process

def fun(a):
    while True:
        print(a)

if __name__ == '__main__':
    p = Process(target=fun, args=(1,)) # that's how you should pass arguments
    p.start()
    p1 = Process(target=fun, args=(2,))  
    p1.start()

output:

1
2
1
2
2
2
2
2
2
1

Upvotes: 1

Related Questions