Oleg
Oleg

Reputation: 403

Python unclear error for multiprocessing

I test python multiprocessing and write simple program:

from multiprocessing import Process
from time import sleep

def f(name):
    print 'hello', name
    x=1
    while True:
        x+=1
        sleep(1)
        print 'subprocess '+str(x)

        if x==10:
            quit()

if __name__ == '__main__':
    p = Process(target=f, args=('bob',))
    p.start()
    x=1
    while True:
        x+=1
        sleep(0.1)
        print 'main process '+str(x)
        if x==100:
            quit()

Its work, but I has little error:

Traceback (most recent call last):
      File "ttt.py", line 17, in <module>
        p.start()
      File "/usr/lib64/python2.6/multiprocessing/process.py", line 104, in start
        self._popen = Popen(self)
      File "/usr/lib64/python2.6/multiprocessing/forking.py", line 99, in __init__
        code = process_obj._bootstrap()
      File "/usr/lib64/python2.6/multiprocessing/process.py", line 242, in _bootstrap
        sys.stderr.write(e.args[0] + '\n')
    TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Upvotes: 1

Views: 731

Answers (1)

Janne Karila
Janne Karila

Reputation: 25207

Use sys.exit() instead of quit(). The latter is meant to be used only in the interactive interpreter.

As Kevin noted, you can use return in f to exit the function normally. This would be perhaps more appropriate.

Upvotes: 1

Related Questions