[issue24911] Context manager of socket.socket is not documented

2016-04-24 Thread Martin Panter

Changes by Martin Panter :


--
resolution:  -> fixed
stage: commit 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



[issue24911] Context manager of socket.socket is not documented

2016-04-23 Thread Roundup Robot

Roundup Robot added the comment:

New changeset d5f7980dd654 by Martin Panter in branch '3.5':
Issue #24911: All socket objects are context managers; update examples
https://hg.python.org/cpython/rev/d5f7980dd654

New changeset 711201953505 by Martin Panter in branch 'default':
Issue #24911: Merge socket context manager doc from 3.5
https://hg.python.org/cpython/rev/711201953505

--
nosy: +python-dev

___
Python tracker 

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



[issue24911] Context manager of socket.socket is not documented

2016-04-03 Thread Martin Panter

Martin Panter added the comment:

FWIW I discovered that socket.close() or __exit__() does not actually raise 
exceptions for cases like EBADF, see Issue 26685.

--

___
Python tracker 

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



[issue24911] Context manager of socket.socket is not documented

2016-02-17 Thread Martin Panter

Martin Panter added the comment:

Thanks for the reviews.

In this new patch, I modified two existing examples, but did not add any new 
example. Does that work for you Yury?

Also modified example code for the socketserver module.

Victor: IMO the “with conn” in the example is not overkill. It ensures the 
client connection socket is cleaned up, which is completely independent of the 
server listening socket s.

What exceptions can you get out of conn.close()? I can only think of unusual 
programming errors like EBADF. I would prefer to remove close() as being 
redundant with the context manager.

--
Added file: http://bugs.python.org/file41943/socket-context.v2.patch

___
Python tracker 

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



[issue24911] Context manager of socket.socket is not documented

2016-02-17 Thread STINNER Victor

STINNER Victor added the comment:

I reviewed the patch.

> It would also be cool if you can add a short code snippet somewhere:

The socket module has examples.

Why not modifying these examples to promote the context manager protocol?

Example:

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s
# use with to ensure that the socket is closed, especially on error
with s:
  s.bind((HOST, PORT))
  s.listen(1)
  conn, addr = s.accept()
  with conn:
print('Connected by', addr)
while True:
data = conn.recv(1024)
if not data: break
conn.sendall(data)
conn.close()


The second "with conn:" is maybe overkill. What do you think?

For a client connection, usually I prefer to explicitly close the socket (even 
if I use "with conn:") to get exception on my ".close()" line, instead of 
getting an exception from the context manager, which is harder to understand.

--
nosy: +haypo

___
Python tracker 

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



[issue24911] Context manager of socket.socket is not documented

2016-02-16 Thread Yury Selivanov

Yury Selivanov added the comment:

The patch looks good.  It would also be cool if you can add a short code 
snippet somewhere:

   sock = socket.socket()
   with sock:
  sock.bind(('127.0.0.1', 8080))
  sock.listen()
  ...

--
nosy: +yselivanov

___
Python tracker 

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



[issue24911] Context manager of socket.socket is not documented

2016-02-16 Thread Berker Peksag

Berker Peksag added the comment:

socket-context.patch looks good to me. There is no need to add a NEWS entry for 
this.

--
nosy: +berker.peksag
stage: patch review -> commit review
versions:  -Python 3.4

___
Python tracker 

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



[issue24911] Context manager of socket.socket is not documented

2015-08-25 Thread Martin Panter

Martin Panter added the comment:

IMO the change notice for create_connection() should be moved to apply to the 
“socket” class, perhaps the “Socket Objects” section. Issue 9794 looks like 
context manager support was added specifically for create_connection(), however 
any socket object, no matter what function is used to create it, should be 
usable the same way for free.

Also, we should explicitly document that exiting the context manager (“with” 
statement) invokes close(), since that affects how the underlying socket is 
closed when makefile() has been used.

--
nosy: +martin.panter

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



[issue24911] Context manager of socket.socket is not documented

2015-08-24 Thread Berker Peksag

Changes by Berker Peksag berker.pek...@gmail.com:


--
keywords: +easy
stage:  - needs patch
type:  - enhancement
versions: +Python 3.5, Python 3.6

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



[issue24911] Context manager of socket.socket is not documented

2015-08-21 Thread zodalahtathi

New submission from zodalahtathi:

socket.socket has a context manager to automatically close the socket with the 
`with` statement: 
https://hg.python.org/cpython/file/d1bf181afa82/Lib/socket.py#l138

However it is not documented, unlike socket.create_connection.

--
assignee: docs@python
components: Documentation
messages: 248979
nosy: docs@python, zodalahtathi
priority: normal
severity: normal
status: open
title: Context manager of socket.socket is not documented
versions: Python 3.4

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