kripken/emscripten — pull request #2944 by aidanhs (2014-10-30 11:33:12+00:00)
Title: Use a plain exception rather than CalledProcessError

Because of http://bugs.python.org/issue9400, pickling of exceptions with required arguments doesn't work. This includes CalledProcessError and means nonzero exit codes are masked by an opaque error message about arguments to __init__ and the test doesn't abort as it should.

You can verify this for yourself with this script:
```
from __future__ import print_function
import multiprocessing
from subprocess import Popen, CalledProcessError
import sys

def loop(x):
vals = ('mycmd', 1)
if error == True:
raise CalledProcessError(*vals)
else:
raise Exception('Command \'%s\' returned non-zero exit status %s' % vals)

if __name__ == '__main__':
if len(sys.argv) < 2 or sys.argv[1] not in ['good', 'bad']:
print("Specify good or bad")
sys.exit(1)
if sys.argv[1] == 'good':
error = False
else:
error = True

pool = multiprocessing.Pool(processes=1)
pool.map(loop, range(1))
```

Example:
```
$ python2 xx.py good
Traceback (most recent call last):
File "xx.py", line 23, in
pool.map(loop, range(1))
File "/usr/lib/python2.7/multiprocessing/pool.py", line 251, in map
return self.map_async(func, iterable, chunksize).get()
File "/usr/lib/python2.7/multiprocessing/pool.py", line 558, in get
raise self._value
Exception: Command 'mycmd' returned non-zero exit status 1
$ python2 xx.py bad
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/lib/python2.7/multiprocessing/pool.py", line 380, in _handle_results
task = get()
TypeError: ('__init__() takes at least 3 arguments (1 given)', , ())

[...hangs...]
```
I assume the reason it hangs is because the exception has occurred in the inner workings of the multiprocessing module. You can't even kill it with ^C - I have success with ^Z and `kill %1`.
It's interesting to note that python 3 does not have this problem (for reasons described on the python ticket).