[issue34066] Possible resource warning in "with open()"

2018-07-13 Thread Jakub Wilk


Change by Jakub Wilk :


--
nosy: +jwilk

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34066] Possible resource warning in "with open()"

2018-07-09 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset eeaae26ce5abce56292330c29459337d6bd57aaf by Serhiy Storchaka in 
branch '3.6':
[3.6] bpo-34066: Disabled interruption before SETUP_WITH and BEFORE_ASYNC_WITH. 
(GH-8159) (GH-8198)
https://github.com/python/cpython/commit/eeaae26ce5abce56292330c29459337d6bd57aaf


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34066] Possible resource warning in "with open()"

2018-07-09 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34066] Possible resource warning in "with open()"

2018-07-09 Thread miss-islington


miss-islington  added the comment:


New changeset f5197ddfd0f2c5da848af57196448810bd18bb82 by Miss Islington (bot) 
in branch '3.7':
bpo-34066: Disabled interruption before SETUP_WITH and BEFORE_ASYNC_WITH. 
(GH-8159)
https://github.com/python/cpython/commit/f5197ddfd0f2c5da848af57196448810bd18bb82


--
nosy: +miss-islington

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34066] Possible resource warning in "with open()"

2018-07-09 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
pull_requests: +7750

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34066] Possible resource warning in "with open()"

2018-07-09 Thread miss-islington


Change by miss-islington :


--
pull_requests: +7749

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34066] Possible resource warning in "with open()"

2018-07-09 Thread Nick Coghlan


Nick Coghlan  added the comment:


New changeset 3f4d90d4d72921f16babd3f52d7df804916af224 by Nick Coghlan (Serhiy 
Storchaka) in branch 'master':
bpo-34066: Disabled interruption before SETUP_WITH and BEFORE_ASYNC_WITH. 
(GH-8159)
https://github.com/python/cpython/commit/3f4d90d4d72921f16babd3f52d7df804916af224


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34066] Possible resource warning in "with open()"

2018-07-08 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Maybe it is worth to disable interrupting before more opcodes. For example for 
fixing a problem with the contextlib.nullcontext example (issue34067) we need 
to disable interrupting before STORE_FAST, LOAD_FAST and JUMP_FORWARD.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34066] Possible resource warning in "with open()"

2018-07-07 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
keywords: +patch
pull_requests: +7723
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34066] Possible resource warning in "with open()"

2018-07-07 Thread Serhiy Storchaka


New submission from Serhiy Storchaka :

The bytecode generated for "with open()":

with open(path) as file:
data = file.read()

  1   0 LOAD_NAME0 (open)
  2 LOAD_NAME1 (path)
  4 CALL_FUNCTION1
  6 SETUP_WITH  14 (to 22)
  8 STORE_NAME   2 (file)

  2  10 LOAD_NAME2 (file)
 12 LOAD_METHOD  3 (read)
 14 CALL_METHOD  0
 16 STORE_NAME   4 (data)
 18 POP_BLOCK
 20 BEGIN_FINALLY
>>   22 WITH_CLEANUP_START
 24 WITH_CLEANUP_FINISH
 26 END_FINALLY
 28 LOAD_CONST   0 (None)
 30 RETURN_VALUE

The execution can be interrupted by Ctrl-C between calling open() and entering 
the 'with' block. In this case the file object will be created, but its 
__enter__ and __exit__ methods will be not executed. As a result it will be 
closed after disappearing a reference to it and a ResourceWarning will be 
emitted.

The solution is disabling interruption before the SETUP_WITH opcode. It is 
already disabled before SETUP_FINALLY and YIELD_FROM. It is worth to disable it 
before BEFORE_ASYNC_WITH for consistency although I don't have examples for it.

See also issue29988.

--
components: Interpreter Core
messages: 321224
nosy: Mark.Shannon, benjamin.peterson, ncoghlan, serhiy.storchaka, yselivanov
priority: normal
severity: normal
status: open
title: Possible resource warning in "with open()"
type: resource usage
versions: Python 3.6, Python 3.7, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com