added autoclose for Python