Thread fixes for py3k