How many kinds of returncode of subprocess.wait()
The doc says the wait() should return 0 or None, but why I get a 255.
This is wrong. The documentation says:
Popen.wait() Wait for child process to terminate. Set and return returncode attribute.
And
Popen.returncode The child return code, set by poll() and wait() (and indirectly by communicate()). A None value indicates that the process hasn’t terminated yet. A negative value -N indicates that the child was terminated by signal N (Unix only).
If the command exits with a non zero exitcode then you will get it.
And the cmd 'put' of hadoop should return 0(when success) and -1(when fail).
This explanation of why you get 255
rather -1
is quite simple and has already be explained here and here. Basically it is due to Java allowing signed 32 bits values as exit code (-1 for us) but a Posix exit status is an unsigned 8 bits value.
To summarize, a non-zero exit code will tell you that the command failed. If you want to check against a special exit code, special care must be taken when the code is not in the 0-255 range.
A return code of 255 means the Hadoop process exited with a -1
return code (why that is I don't know).
The reason wait()
doesn't give you -1 is because negative numbers are reserved for cases when the subprocess exited due to a signal (if it exited due to, say, signal 11, the return code would have been -11).