more fault-tolerant sample
port to Python3