text_combined: antoine pitrou slvkzycypitrounet hello seems subject quite bit history tim peters demonstrated problem 2003 message httpmailpythonorgpipermailpythondev2003june036537html short python file objects release gil calling c stdlib function embedded file pointer unfortunately another thread calls fclose file pointer concurrently contents pointed become garbage interpreter process crashes using file object two threads running pure python code crash interpreter another easiertosolve problem file pointer stored file object could become null point used another thread problem could store file pointer local variable releasing gil et voilà discussion time possible resolution ive tried fix problem ive come think satisfying solution sum following bullet points file object gets dedicated counter incremented bject releases gil decremented gil taken thus counter keeps track many running unlocked sections code using particular file object please note counter doesnt need lock since modified gilprotected sections close method aforementioned counter greater 0 refuse call fclose instead raise ioerror may seem like worrying semantic change dont think following reasons 1 closed file pointer anyway interpreter would likely crash another thread would using garbage data thats trying fix 2 close raises ioerror called later worse fclose called file object garbage collected 3 close already raise ioerror fclose fails whatever reason although sure probably rare 4 doesnt seem wrong notify programmer code unsafe patch attached httpbugspythonorgissue815646 addresses least hope potential problems pure python code threads file object doesnt try fix c extensions using pyfile_asfile api dirty things file pointer could second step approach accepted noted 2003 discussions would probably involve new api whether want introduce api python 2x python 30 different io model anyway left open discussion regards antoine _______________________________________________ pythondev mailing list pythondevpythonorg httpmailpythonorgmailmanlistinfopythondev unsubscribe httpmailpythonorgmailmanoptionspythondevpythondev40tangomucom thu 07 aug 2008 035936 0000 pythondev threadsafe file objects return