Fix python multithread bug.