0

I use multiprocessing to set up 2 process.
Here is my code:

import multiprocessing 

def aaa():
    while True:
        print('aaa')

def bbb():
    while True:
        print('bbb')


if __name__=='__main__':
    p1=multiprocessing.Process(target=aaa())
    p2=multiprocessing.Process(target=bbb())
    p1.start
    p2.start
    p1.join
    p2.join

I expect it will print:

'aaa','bbb','aaa','bbb','aaa','bbb','aaa','bbb','aaa','bbb','aaa','bbb',

Why does it only print aaa, but not bbb ?
thank you!

SherylHohman
  • 16,580
  • 17
  • 88
  • 94
  • `start` and `join` are functions, you need to call them instead of just stating their names: `p1.start()`, note the parentheses. – Hai Vu Apr 15 '18 at 15:04

1 Answers1

0

You're calling aaa, not passing it to Process.

import multiprocessing 

def aaa():
    while True:
        print('aaa')

def bbb():
    while True:
        print('bbb')


if __name__=='__main__':
    p1=multiprocessing.Process(target=aaa)
    p2=multiprocessing.Process(target=bbb)
    p1.start()
    p2.start()
    p1.join()
    p2.join()
Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96