Message262438
> I think we should use one of Martin's option. If there are any issues with garbage collecting, we should fix the garbage collector.
Ok, here is a new simpler proposition: remove all _dealloc_warn() method, and simply emit the ResourceWarning in IOBase finalizer.
With this change, all objects which inherit from io.IOBase (or _pyio.IOBase) now emits a ResourceWarning if they are not closed explicitly. You have to override the __del__() method to prevent this warning.
A lot of new objects start to log ResourceWarning: io.SocketIO, _pyio.TextIOWrapper, io.BytesIO, http.client.HTTPResponse, etc.
For io.BytesIO, I fixed the code to inherit correctly IOBase finalizer.
--
A lot of tests start to fail because they emit a lot of ResourceWarning warnings. I don't know yet if it's a feature or a bug :-)
--
With the patch, Python starts to logs warnings like:
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='<stdin>' mode='r' encoding='UTF-8'>
You can use my patch of the issue #26642 to fix these warnings.
ResourceWarning is emited even if FileIO.closefd is false.
Note: It looks like the ResourceWarning is not always displayed. Yet another bug? |
|
| Date |
User |
Action |
Args |
| 2016-03-25 13:22:05 | vstinner | set | recipients:
+ vstinner, pitrou, Arfrever, akira, martin.panter, piotr.dobrogost, serhiy.storchaka |
| 2016-03-25 13:22:05 | vstinner | set | messageid: <1458912125.11.0.211388011359.issue19829@psf.upfronthosting.co.za> |
| 2016-03-25 13:22:05 | vstinner | link | issue19829 messages |
| 2016-03-25 13:22:04 | vstinner | create | |
|