[issue43944] Processes in Python 3.9 exiting with code 1 when It's created inside a ThreadPoolExecutor

2022-04-08 Thread Thomas Grainger


Thomas Grainger  added the comment:

the problem is multiprocessing/process is calling threading._shutdown which 
tries to join its own thread, because concurrent.futures.thread._threads_queues 
contains the main thread in the subprocess


  File 
"/home/graingert/miniconda3/envs/dask-distributed/lib/python3.10/multiprocessing/process.py",
 line 333, in _bootstrap
threading._shutdown()
  File 
"/home/graingert/miniconda3/envs/dask-distributed/lib/python3.10/threading.py", 
line 1530, in _shutdown
atexit_call()
  File 
"/home/graingert/miniconda3/envs/dask-distributed/lib/python3.10/concurrent/futures/thread.py",
 line 31, in _python_exit
t.join()
  File 
"/home/graingert/miniconda3/envs/dask-distributed/lib/python3.10/threading.py", 
line 1086, in join
raise RuntimeError("cannot join current thread")

--
nosy: +graingert

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



[issue45563] inspect.getframeinfo() doesn't handle frames without lineno

2022-03-22 Thread Thomas Grainger


Change by Thomas Grainger :


--
keywords: +patch
nosy: +graingert
nosy_count: 4.0 -> 5.0
pull_requests: +30134
stage: resolved -> patch review
pull_request: https://github.com/python/cpython/pull/32044

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



[issue47085] missing frame.f_lineno on JUMP_ABSOLUTE

2022-03-21 Thread Thomas Grainger


New submission from Thomas Grainger :

the following code prints:

import sys
import dis

import pprint

def demo():
for i in range(1):
if i >= 0:
pass


class Tracer:
def __init__(self):
self.events = []

def trace(self, frame, event, arg):
self.events.append((frame.f_lineno, frame.f_lasti, event))
frame.f_trace_lines = True
frame.f_trace_opcodes = True
return self.trace

def main():
t = Tracer()
old_trace = sys.gettrace()
try:
sys.settrace(t.trace)
demo()
finally:
sys.settrace(old_trace)
dis.dis(demo)
pprint.pp(t.events)


if __name__ == "__main__":
sys.exit(main())



  7   0 LOAD_GLOBAL  0 (range)
  2 LOAD_CONST   1 (1)
  4 CALL_FUNCTION1
  6 GET_ITER
>>8 FOR_ITER 7 (to 24)
 10 STORE_FAST   0 (i)

  8  12 LOAD_FAST0 (i)
 14 LOAD_CONST   2 (0)
 16 COMPARE_OP   5 (>=)
 18 POP_JUMP_IF_FALSE   11 (to 22)

  9  20 NOP
>>   22 JUMP_ABSOLUTE4 (to 8)

  7 >>   24 LOAD_CONST   0 (None)
 26 RETURN_VALUE
[(6, -1, 'call'),
 (7, 0, 'line'),
 (7, 0, 'opcode'),
 (7, 2, 'opcode'),
 (7, 4, 'opcode'),
 (7, 6, 'opcode'),
 (7, 8, 'opcode'),
 (7, 10, 'opcode'),
 (8, 12, 'line'),
 (8, 12, 'opcode'),
 (8, 14, 'opcode'),
 (8, 16, 'opcode'),
 (8, 18, 'opcode'),
 (9, 20, 'line'),
 (9, 20, 'opcode'),
 (None, 22, 'opcode'),
 (7, 8, 'line'),
 (7, 8, 'opcode'),
 (7, 24, 'opcode'),
 (7, 26, 'opcode'),
 (7, 26, 'return')]


but I'd expect  (9, 22, 'opcode') instead of (None, 22, 'opcode'),

--
messages: 415697
nosy: graingert
priority: normal
severity: normal
status: open
title: missing frame.f_lineno on JUMP_ABSOLUTE
versions: Python 3.10, Python 3.11

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



[issue47025] bytes do not work on sys.path

2022-03-16 Thread Thomas Grainger


Thomas Grainger  added the comment:

> I'd advocate for not supporting bytes paths and instead updating the 
> documentation to require strings.

I've got PR GH-31934 started to do this

--
message_count: 8.0 -> 9.0
pull_requests: +30026
pull_request: https://github.com/python/cpython/pull/31934

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



[issue47026] BytesWarning in zipimport paths on sys.path

2022-03-15 Thread Thomas Grainger


New submission from Thomas Grainger :

importing from a bytes zipimport path on sys.path results in a BytesWarning: 
Comparison between bytes and string

running the reproducer with `python -b` shows:
python -b zipfile_demo.py 
:1345: BytesWarning: Comparison between 
bytes and string

see also https://bugs.python.org/issue47025

--
components: Library (Lib)
files: zipfile_demo.py
messages: 415245
nosy: graingert
priority: normal
severity: normal
status: open
title: BytesWarning in zipimport paths on sys.path
versions: Python 3.10, Python 3.11, Python 3.9
Added file: https://bugs.python.org/file50680/zipfile_demo.py

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



[issue47025] bytes do not work on sys.path

2022-03-15 Thread Thomas Grainger


Thomas Grainger  added the comment:

zipimporter.zipimporter handles non-bytes paths here: 
https://github.com/python/cpython/blob/2cf7f865f099db11cc6903b334d9c376610313e8/Lib/zipimport.py#L65-L67
 I think FileFinder should do the same

--

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



[issue47025] bytes do not work on sys.path

2022-03-15 Thread Thomas Grainger


Thomas Grainger  added the comment:

interestingly bytes filenames pointing to zip files on sys.path do support 
bytes (see zipfile_demo.py)

--
Added file: https://bugs.python.org/file50679/zipfile_demo.py

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



[issue47025] bytes do not work on sys.path

2022-03-15 Thread Thomas Grainger


Thomas Grainger  added the comment:

https://docs.python.org/3/reference/import.html#path-entry-finders says "The 
encoding of bytes entries is determined by the individual path entry finders." 
see 
https://github.com/python/cpython/commit/82c1c781c7ee6496bd4c404b7ba972eed5dbcb12

--

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



[issue47025] bytes do not work on sys.path

2022-03-15 Thread Thomas Grainger


Thomas Grainger  added the comment:

this is a regression from 3.2:

```
Python 3.2.6 (default, Jan 18 2016, 19:21:14) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tempfile
>>> tempfile.TemporaryDirectory()

>>> v = _
>>> tmp_dir = str(v.__enter__())
>>> tmp_dir
'/tmp/tmpd4jzut'
>>> f = open(tmp_dir + "/module.py", "w")
>>> f.write("def function():\nreturn 1\n")
29
>>> f.close()
>>> import sys
>>> sys.path.append(tmp_dir.encode())
>>> import module
>>> module

>>> 
```

--

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



[issue47025] bytes do not work on sys.path

2022-03-15 Thread Thomas Grainger


Change by Thomas Grainger :


--
keywords: +patch
pull_requests: +29993
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/31897

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



[issue47025] bytes do not work on sys.path

2022-03-15 Thread Thomas Grainger


Change by Thomas Grainger :


--
components: +Library (Lib)
versions: +Python 3.10, Python 3.11, Python 3.9

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



[issue47025] bytes do not work on sys.path

2022-03-15 Thread Thomas Grainger


New submission from Thomas Grainger :

importing a module with bytes in `sys.path` fails with:

  File "", line 182, in _path_isabs
TypeError: startswith first arg must be bytes or a tuple of bytes, not str

(see reproducer in attached demo.py)

however `sys.path` is documented as supporting bytes "Only strings and bytes 
should be added to sys.path; all other data types are ignored during import." 
https://docs.python.org/3/library/sys.html?highlight=Only%20strings%20and%20bytes#sys.path

bytes are allowed in PathFinder._find_spec 
https://github.com/python/cpython/blob/2cf7f865f099db11cc6903b334d9c376610313e8/Lib/importlib/_bootstrap_external.py#L1460-L1462
 but perhaps they should be ignored or explicitly fsdecoded ? 


see also:
https://bugs.python.org/issue32642
https://github.com/python/importlib_metadata/issues/372#issuecomment-1067799424

--
files: demo.py
messages: 415233
nosy: graingert
priority: normal
severity: normal
status: open
title: bytes do not work on sys.path
Added file: https://bugs.python.org/file50678/demo.py

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



[issue43923] Can't create generic NamedTuple as of py3.9

2022-03-05 Thread Thomas Grainger

Thomas Grainger  added the comment:

The main advantage for my usecase is support for heterogeneous unpacking

On Sat, Mar 5, 2022, 6:04 PM Alex Waygood  wrote:

>
> Alex Waygood  added the comment:
>
> I sense we'll have to agree to disagree on the usefulness of NamedTuples
> in the age of dataclasses :)
>
> For me, I find the simplicity of the underlying idea behind namedtuples —
> "tuples with some properties bolted on" — very attractive. Yes, standard
> tuples are more performant, but it's great to have a tool in the arsenal
> that's essentially the same as a tuple (and is backwards-compatible with a
> tuple, for APIs that require a tuple), but can also, like dataclasses, be
> self-documenting. (You're right that DoneAndNotDoneFutures isn't a great
> example of this.)
>
> But I agree that this shouldn't be a priority if it's hard to accomplish;
> and there'll certainly be no complaints from me if energy is invested into
> making dataclasses faster.
>
> --
>
> ___
> Python tracker 
> <https://bugs.python.org/issue43923>
> ___
>

--

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



[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2022-02-23 Thread Thomas Grainger


Thomas Grainger  added the comment:

there could be multiple messages here

perhaps it could be:

```
finally:
# Must reacquire lock even if wait is cancelled
cancelled = []
while True:
try:
await self.acquire()
break
except exceptions.CancelledError as e:
cancelled.append(e)

if len(cancelled) > 1:
raise ExceptionGroup("Cancelled", cancelled)
if cancelled:
raise cancelled[0]
```

--

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



[issue46827] asyncio SelectorEventLoop.sock_connect fails with a UDP socket

2022-02-22 Thread Thomas Grainger


Change by Thomas Grainger :


--
keywords: +patch
pull_requests: +29629
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/31499

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



[issue46827] asyncio SelectorEventLoop.sock_connect fails with a UDP socket

2022-02-22 Thread Thomas Grainger


New submission from Thomas Grainger :

the following code:

import socket
import asyncio

async def amain():
with socket.socket(family=socket.AF_INET, proto=socket.IPPROTO_UDP, 
type=socket.SOCK_DGRAM) as sock:
sock.setblocking(False)
await asyncio.get_running_loop().sock_connect(sock, ("google.com", 
"443"))

asyncio.run(amain())


fails with:

Traceback (most recent call last):
  File "/home/graingert/projects/test_foo.py", line 9, in 
asyncio.run(amain())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 641, in 
run_until_complete
return future.result()
  File "/home/graingert/projects/test_foo.py", line 7, in amain
await asyncio.get_running_loop().sock_connect(sock, ("google.com", "443"))
  File "/usr/lib/python3.10/asyncio/selector_events.py", line 496, in 
sock_connect
resolved = await self._ensure_resolved(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1395, in 
_ensure_resolved
return await loop.getaddrinfo(host, port, family=family, type=type,
  File "/usr/lib/python3.10/asyncio/base_events.py", line 855, in getaddrinfo
return await self.run_in_executor(
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.10/socket.py", line 955, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -7] ai_socktype not supported

--
components: asyncio
messages: 413709
nosy: asvetlov, graingert, yselivanov
priority: normal
severity: normal
status: open
title: asyncio SelectorEventLoop.sock_connect fails with a UDP socket
versions: Python 3.10, Python 3.11, Python 3.9

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



[issue46824] use AI_NUMERICHOST | AI_NUMERICSERV to skip getaddrinfo thread in asyncio

2022-02-22 Thread Thomas Grainger


Thomas Grainger  added the comment:

hello, it's actually a bit of a round about context, but it was brought up on a 
tornado issue where I was attempting to port the asyncio optimization to 
tornado: 
https://github.com/tornadoweb/tornado/issues/3113#issuecomment-1041019287

I think it would be better to use this AI_NUMERICHOST | AI_NUMERICSERV 
optimization from trio everywhere instead

--

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



[issue46824] use AI_NUMERICHOST | AI_NUMERICSERV to skip getaddrinfo thread in asyncio

2022-02-22 Thread Thomas Grainger


Change by Thomas Grainger :


--
keywords: +patch
pull_requests: +29627
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/31497

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



[issue46824] use AI_NUMERICHOST | AI_NUMERICSERV to skip getaddrinfo thread in asyncio

2022-02-22 Thread Thomas Grainger


New submission from Thomas Grainger :

now that the getaddrinfo lock has been removed on all platforms the numeric 
only host resolve in asyncio could be moved back into BaseEventLoop.getaddrinfo

--
components: asyncio
messages: 413699
nosy: asvetlov, graingert, yselivanov
priority: normal
severity: normal
status: open
title: use AI_NUMERICHOST | AI_NUMERICSERV to skip getaddrinfo thread in asyncio
type: enhancement

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



[issue42752] multiprocessing Queue leaks a file descriptor associated with the pipe writer (#33081 still a problem)

2022-02-17 Thread Thomas Grainger


Change by Thomas Grainger :


--
nosy: +graingert, vstinner

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



[issue44863] Allow TypedDict to inherit from Generics

2022-02-03 Thread Thomas Grainger


Thomas Grainger  added the comment:

there's a thread on typing-sig for this now: 
https://mail.python.org/archives/list/typing-...@python.org/thread/I7P3ER2NH7SENVMIXK74U6L4Z5JDLQGZ/#I7P3ER2NH7SENVMIXK74U6L4Z5JDLQGZ

--
nosy: +graingert

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



[issue46522] concurrent.futures.__getattr__ raises the wrong AttributeError message

2022-01-25 Thread Thomas Grainger


Thomas Grainger  added the comment:

this also applies to io and _pyio

--

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



[issue46522] concurrent.futures.__getattr__ raises the wrong AttributeError message

2022-01-25 Thread Thomas Grainger


New submission from Thomas Grainger :

>>> import types
>>> types.ModuleType("concurrent.futures").missing_attribute
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: module 'concurrent.futures' has no attribute 'missing_attribute'
>>> import concurrent.futures
>>> concurrent.futures.missing_attribute
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/home/graingert/miniconda3/lib/python3.9/concurrent/futures/__init__.py", line 
53, in __getattr__
raise AttributeError(f"module {__name__} has no attribute {name}")
AttributeError: module concurrent.futures has no attribute missing_attribute

--
messages: 411611
nosy: graingert
priority: normal
pull_requests: 29069
severity: normal
status: open
title: concurrent.futures.__getattr__ raises the wrong AttributeError message
versions: Python 3.10, Python 3.11, Python 3.9

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



[issue38415] @asynccontextmanager decorated functions are not callable like @contextmanager

2021-12-22 Thread Thomas Grainger


Thomas Grainger  added the comment:

actually it was already done in 13 months!

--

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



[issue38415] @asynccontextmanager decorated functions are not callable like @contextmanager

2021-12-22 Thread Thomas Grainger


Change by Thomas Grainger :


--
nosy: +graingert
nosy_count: 3.0 -> 4.0
pull_requests: +28454
pull_request: https://github.com/python/cpython/pull/30233

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



[issue45996] Worse error from asynccontextmanager in Python 3.10

2021-12-19 Thread Thomas Grainger


Thomas Grainger  added the comment:

> Actually I don't agree with Thomas's logic... his argument feels like 
> consistency for its own sake.

Do you expect sync and async contextmanagers to act differently?

Why would sync contextmanagers raise AttributeError and async contextmanagers 
raise a RuntimeError?

If it's sensible to guard against invalid re-entry for async contextmanagers 
then I think it's sensible to apply the same guard to sync contextmanagers.

--

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



[issue45996] Worse error from asynccontextmanager in Python 3.10

2021-12-06 Thread Thomas Grainger


Thomas Grainger  added the comment:

you can see the analogous sync contextmanager issue on python3.6 with:

```
import logging
from contextlib import contextmanager

@contextmanager
def foo():
yield


def test():
f = foo()
f.__enter__()
f.__enter__()

test()
```

on python3.7+ you get the bpo-30306 behaviour

```
Traceback (most recent call last):
  File "sync.py", line 14, in 
test()
  File "sync.py", line 12, in test
f.__enter__()
  File "/usr/lib/python3.8/contextlib.py", line 111, in __enter__
del self.args, self.kwds, self.func
AttributeError: args
```

and python3.6 you get the same sort of error you see now for 
asynccontextmanagers:

```
Traceback (most recent call last):
  File "sync.py", line 14, in 
test()
  File "sync.py", line 12, in test
f.__enter__()
  File "/usr/lib/python3.6/contextlib.py", line 83, in __enter__
raise RuntimeError("generator didn't yield") from None
RuntimeError: generator didn't yield
```

--

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



[issue45996] Worse error from asynccontextmanager in Python 3.10

2021-12-06 Thread Thomas Grainger


Thomas Grainger  added the comment:

I see the change here: 
https://github.com/python/cpython/commit/1c5c9c89ffc36875afaf4c3cc6a716d4bd089bbf#diff-e00601a380ba6c916ba4333277fe6ea43d2477804002ab1ae64480f80fec8e3aR177-R179

this is intentionally implementing https://bugs.python.org/issue30306 for 
asynccontextmanagers that was initially missing

--

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



[issue45996] Worse error from asynccontextmanager in Python 3.10

2021-12-06 Thread Thomas Grainger


Thomas Grainger  added the comment:

ah I can repeat this on python3.8.10 trio but not python3.9.9 trio:

```
import logging
import trio
from contextlib import asynccontextmanager

@asynccontextmanager
async def foo():
await trio.sleep(1)
yield


async def test():
async with trio.open_nursery() as n:
f = foo()
n.start_soon(f.__aenter__)
n.start_soon(f.__aenter__)

trio.run(test)

```

```
Traceback (most recent call last):
  File "bar.py", line 17, in 
trio.run(test)
  File 
"/home/graingert/.virtualenvs/osirium-main/lib/python3.8/site-packages/trio/_core/_run.py",
 line 1932, in run
raise runner.main_task_outcome.error
  File "bar.py", line 15, in test
n.start_soon(f.__aenter__)
  File 
"/home/graingert/.virtualenvs/osirium-main/lib/python3.8/site-packages/trio/_core/_run.py",
 line 815, in __aexit__
raise combined_error_from_nursery
  File "/usr/lib/python3.8/contextlib.py", line 171, in __aenter__
return await self.gen.__anext__()
RuntimeError: anext(): asynchronous generator is already running
```

--

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



[issue45996] Worse error from asynccontextmanager in Python 3.10

2021-12-06 Thread Thomas Grainger


Thomas Grainger  added the comment:

or consider the trio version:

```
import logging
import trio
from contextlib import asynccontextmanager

@asynccontextmanager
async def foo():
await trio.sleep(1)
yield


async def test():
async with trio.open_nursery() as n:
f = foo()
n.start_soon(f.__aenter__)
n.start_soon(f.__aenter__)

trio.run(test)
```

```
Traceback (most recent call last):
  File "/home/graingert/projects/examples/bar.py", line 17, in 
trio.run(test)
  File 
"/home/graingert/.virtualenvs/testing39/lib/python3.9/site-packages/trio/_core/_run.py",
 line 1932, in run
raise runner.main_task_outcome.error
  File "/home/graingert/projects/examples/bar.py", line 15, in test
n.start_soon(f.__aenter__)
  File 
"/home/graingert/.virtualenvs/testing39/lib/python3.9/site-packages/trio/_core/_run.py",
 line 815, in __aexit__
raise combined_error_from_nursery
  File "/usr/lib/python3.9/contextlib.py", line 179, in __aenter__
del self.args, self.kwds, self.func
AttributeError: args
```

--

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



[issue45996] Worse error from asynccontextmanager in Python 3.10

2021-12-06 Thread Thomas Grainger


Thomas Grainger  added the comment:

I think `AttributeError: args` is the desired/expected behaviour

consider the sync version:

```
import logging
from asyncio import sleep, gather, run
from contextlib import asynccontextmanager, contextmanager

@contextmanager
def foo():
yield


def test():
f = foo()
f.__enter__()
f.__enter__()

test()
```

```
Traceback (most recent call last):
  File "/home/graingert/projects/example/sync.py", line 15, in 
test()
  File "/home/graingert/projects/example/sync.py", line 13, in test
f.__enter__()
  File "/usr/lib/python3.9/contextlib.py", line 117, in __enter__
del self.args, self.kwds, self.func
AttributeError: args
```

--

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



[issue25625] "chdir" Contex manager for pathlib

2021-10-20 Thread Thomas Grainger


Change by Thomas Grainger :


--
nosy: +graingert
nosy_count: 10.0 -> 11.0
pull_requests: +27360
pull_request: https://github.com/python/cpython/pull/29091

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



[issue45435] delete misleading faq entry about atomic operations

2021-10-12 Thread Thomas Grainger


Thomas Grainger  added the comment:

it's as part of this discussion in 
https://mail.python.org/archives/list/python-...@python.org/thread/ABR2L6BENNA6UPSPKV474HCS4LWT26GY/#IAOCDDCJ653NBED3G2J2YBWD7HHPFHT6
 and others in #python-dev 

specifically 
https://github.com/python/cpython/blob/2f92e2a590f0e5d2d3093549f5af9a4a1889eb5a/Objects/dictobject.c#L2582-L2586

regarding if any of the items are builtins or not: the faq entry lists (L, L1, 
L2 are lists, D, D1, D2 are dicts, x, y are objects, i, j are ints) so I read 
that to mean x and y are user defined objects with user defined comparison and 
equality methods

--

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



[issue45435] delete misleading faq entry about atomic operations

2021-10-11 Thread Thomas Grainger


Change by Thomas Grainger :


--
keywords: +patch
pull_requests: +27181
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/28886

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



[issue45435] delete misleading faq entry about atomic operations

2021-10-11 Thread Thomas Grainger


Change by Thomas Grainger :


--
assignee: docs@python
components: Documentation
nosy: docs@python, graingert
priority: normal
severity: normal
status: open
title: delete misleading faq entry about atomic operations

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



[issue45390] asyncio.Task doesn't propagate CancelledError() exception correctly.

2021-10-07 Thread Thomas Grainger


Thomas Grainger  added the comment:

afaik this is intentional https://bugs.python.org/issue31033

--
nosy: +graingert

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



[issue45279] avoid redundant _commit_removals pending_removals guard

2021-09-24 Thread Thomas Grainger


Change by Thomas Grainger :


--
keywords: +patch
pull_requests: +26930
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/28546

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



[issue45279] avoid redundant _commit_removals pending_removals guard

2021-09-24 Thread Thomas Grainger


New submission from Thomas Grainger :

refactor to avoid redundant _commit_removals pending_removals guard

--
components: Library (Lib)
messages: 402554
nosy: graingert
priority: normal
severity: normal
status: open
title: avoid redundant _commit_removals pending_removals guard
versions: Python 3.10, Python 3.11, Python 3.9

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



[issue45278] RuntimeError on race on weakset concurrent iteration

2021-09-24 Thread Thomas Grainger


Change by Thomas Grainger :


--
nosy: +graingert

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



[issue45276] avoid try 1000 in asyncio all_tasks by making weak collection .copy() atomic

2021-09-24 Thread Thomas Grainger


Change by Thomas Grainger :


--
keywords: +patch
pull_requests: +26925
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/28541

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



[issue45276] avoid try 1000 in asyncio all_tasks by making weak collection .copy() atomic

2021-09-24 Thread Thomas Grainger


New submission from Thomas Grainger :

the weak collections should have the same threadsafe/thread unsafe guarantees 
as their strong reference counterparts - eg dict.copy and set.copy are atomic 
and so the weak versions should be atomic also

--
components: Interpreter Core, asyncio
messages: 402544
nosy: asvetlov, graingert, yselivanov
priority: normal
severity: normal
status: open
title: avoid try 1000 in asyncio all_tasks by making weak collection .copy() 
atomic
versions: Python 3.10, Python 3.11, Python 3.9

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



[issue44962] asyncio.create_task weakrefset race condition

2021-08-24 Thread Thomas Grainger


Change by Thomas Grainger :


--
nosy: +pitrou

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



[issue44962] asyncio.create_task weakrefset race condition

2021-08-23 Thread Thomas Grainger


Thomas Grainger  added the comment:

> weakref.WeakSet is not thread-safe,  which means concurrent create_task's in 
> different threads (even on separate event loops) is not safe.

actually it looks like WeakSet is *supposed* to be thread-safe


```
import patchy

patchy.patch(
"weakref:WeakSet._commit_removals",
"""\
@@ -1,5 +1,10 @@
 def _commit_removals(self):
-l = self._pending_removals
+pop = self._pending_removals.pop
 discard = self.data.discard
-while l:
-discard(l.pop())
+while True:
+try:
+item = pop()
+except IndexError:
+return
+else:
+discard(item)
"""
)

import itertools
import asyncio
import concurrent.futures
import sys
import threading

threads = 200

def test_all_tasks_threading() -> None:
async def foo() -> None:
await asyncio.sleep(0)

async def create_tasks() -> None:
for i in range(1000):
asyncio.create_task(foo())

await asyncio.sleep(0)

results = []
with concurrent.futures.ThreadPoolExecutor(threads) as tpe:
for f in concurrent.futures.as_completed(
tpe.submit(asyncio.run, create_tasks()) for i in range(threads)
):
results.append(f.result())
assert results == [None] * threads


def main():
for i in itertools.count():
test_all_tasks_threading()
print(f"worked {i}")
return 0


if __name__ == "__main__":
sys.exit(main())
```

--

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



[issue44962] asyncio.create_task weakrefset race condition

2021-08-23 Thread Thomas Grainger


Change by Thomas Grainger :


--
pull_requests: +26373
pull_request: https://github.com/python/cpython/pull/27921

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



[issue44962] asyncio.create_task weakrefset race condition

2021-08-23 Thread Thomas Grainger


Change by Thomas Grainger :


--
keywords: +patch
pull_requests: +26365
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/27909

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



[issue44963] anext_awaitable is not a collections.abc.Generator

2021-08-21 Thread Thomas Grainger


Change by Thomas Grainger :


--
nosy: +pablogsal

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



[issue44963] anext_awaitable is not a collections.abc.Generator

2021-08-20 Thread Thomas Grainger


Thomas Grainger  added the comment:

it also fails with asyncio.create_task

```
import asyncio

async def agen():
yield

async def main():
p = agen()
await asyncio.create_task(anext(p, 'finished'))

asyncio.run(main())
```

```
Traceback (most recent call last):
  File "/home/graingert/projects/datapraxis/analysis/foo.py", line 10, in 

asyncio.run(main())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 641, in 
run_until_complete
return future.result()
  File "/home/graingert/projects/asyncio-demo/foo.py", line 8, in main
await asyncio.create_task(anext(p, 'finished'))
  File "/usr/lib/python3.10/asyncio/tasks.py", line 337, in create_task
task = loop.create_task(coro)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 433, in create_task
task = tasks.Task(coro, loop=self, name=name)
TypeError: a coroutine was expected, got 
```


there's also a problem with cancelling and aclosing an async gen this way:

```
import asyncio
import contextlib

async def agen():
await asyncio.sleep(1)
yield

async def main():
async with contextlib.aclosing(agen()) as p:
asyncio.current_task().cancel()
try:
await anext(p, 'finished')
except asyncio.CancelledError:
pass

asyncio.run(main())
```

```
an error occurred during closing of asynchronous generator 
asyncgen: 
Traceback (most recent call last):
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 641, in 
run_until_complete
return future.result()
  File "/home/graingert/projects/asyncio-demo/foo.py", line 9, in main
async with contextlib.aclosing(agen()) as p:
  File "/usr/lib/python3.10/contextlib.py", line 366, in __aexit__
await self.thing.aclose()
RuntimeError: aclose(): asynchronous generator is already running

During handling of the above exception, another exception occurred:

RuntimeError: aclose(): asynchronous generator is already running
Traceback (most recent call last):
  File "/home/graingert/projects/datapraxis/analysis/foo.py", line 16, in 

asyncio.run(main())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 641, in 
run_until_complete
return future.result()
  File "/home/graingert/projects/asyncio-demo/foo.py", line 9, in main
async with contextlib.aclosing(agen()) as p:
  File "/usr/lib/python3.10/contextlib.py", line 366, in __aexit__
await self.thing.aclose()
RuntimeError: aclose(): asynchronous generator is already running
```

--
nosy: +graingert

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



[issue44962] asyncio.create_task weakrefset race condition

2021-08-20 Thread Thomas Grainger


Thomas Grainger  added the comment:

interestingly 3.10 didn't show:

sys:1: RuntimeWarning: coroutine 'BaseEventLoop.shutdown_asyncgens' was never 
awaited

--

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



[issue44962] asyncio.create_task weakrefset race condition

2021-08-20 Thread Thomas Grainger


Thomas Grainger  added the comment:

still happens on 3.10 even though there's an `with _IterationGuard`

```
worked 0
Traceback (most recent call last):
  File "/home/graingert/projects/asyncio-demo/demo.py", line 36, in 
sys.exit(main())
  File "/home/graingert/projects/asyncio-demo/demo.py", line 30, in main
test_all_tasks_threading()
  File "/home/graingert/projects/asyncio-demo/demo.py", line 24, in 
test_all_tasks_threading
results.append(f.result())
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 438, in result
return self.__get_result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 390, in 
__get_result
raise self._exception
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.10/asyncio/runners.py", line 47, in run
_cancel_all_tasks(loop)
  File "/usr/lib/python3.10/asyncio/runners.py", line 56, in _cancel_all_tasks
to_cancel = tasks.all_tasks(loop)
  File "/usr/lib/python3.10/asyncio/tasks.py", line 53, in all_tasks
tasks = list(_all_tasks)
  File "/usr/lib/python3.10/_weakrefset.py", line 60, in __iter__
with _IterationGuard(self):
  File "/usr/lib/python3.10/_weakrefset.py", line 33, in __exit__
w._commit_removals()
  File "/usr/lib/python3.10/_weakrefset.py", line 57, in _commit_removals
discard(l.pop())
IndexError: pop from empty list
```

--

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



[issue44962] asyncio.create_task weakrefset race condition

2021-08-20 Thread Thomas Grainger


Change by Thomas Grainger :


--
versions: +Python 3.10

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



[issue44962] asyncio.create_task weakrefset race condition

2021-08-20 Thread Thomas Grainger


Change by Thomas Grainger :


--
versions: +Python 3.7

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



[issue44962] asyncio.create_task weakrefset race condition

2021-08-20 Thread Thomas Grainger


New submission from Thomas Grainger :

with the following demo script I can get a IndexError: pop from empty list

```
import itertools
import asyncio
import concurrent.futures
import sys
import threading

threads = 200

def test_all_tasks_threading() -> None:
async def foo() -> None:
await asyncio.sleep(0)

async def create_tasks() -> None:
for i in range(1000):
asyncio.create_task(foo())

await asyncio.sleep(0)

results = []
with concurrent.futures.ThreadPoolExecutor(threads) as tpe:
for f in concurrent.futures.as_completed(
tpe.submit(asyncio.run, create_tasks()) for i in range(threads)
):
results.append(f.result())
assert results == [None] * threads


def main():
for i in itertools.count():
test_all_tasks_threading()
print(f"worked {i}")
return 0


if __name__ == "__main__":
sys.exit(main())
```



```
worked 0
worked 1
worked 2
worked 3
worked 4
worked 5
worked 6
worked 7
worked 8
worked 9
worked 10
worked 11
worked 12
worked 13
worked 14
worked 15
worked 16
worked 17
worked 18
Traceback (most recent call last):
  File "/home/graingert/projects/asyncio-demo/demo.py", line 36, in 
sys.exit(main())
  File "/home/graingert/projects/asyncio-demo/demo.py", line 30, in main
test_all_tasks_threading()
  File "/home/graingert/projects/asyncio-demo/demo.py", line 24, in 
test_all_tasks_threading
results.append(f.result())
  File "/usr/lib/python3.9/concurrent/futures/_base.py", line 438, in result
return self.__get_result()
  File "/usr/lib/python3.9/concurrent/futures/_base.py", line 390, in 
__get_result
raise self._exception
  File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.9/asyncio/runners.py", line 48, in run
loop.run_until_complete(loop.shutdown_asyncgens())
  File "/usr/lib/python3.9/asyncio/base_events.py", line 621, in 
run_until_complete
future = tasks.ensure_future(future, loop=self)
  File "/usr/lib/python3.9/asyncio/tasks.py", line 667, in ensure_future
task = loop.create_task(coro_or_future)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 433, in create_task
task = tasks.Task(coro, loop=self, name=name)
  File "/usr/lib/python3.9/_weakrefset.py", line 84, in add
self._commit_removals()
  File "/usr/lib/python3.9/_weakrefset.py", line 57, in _commit_removals
discard(l.pop())
IndexError: pop from empty list
sys:1: RuntimeWarning: coroutine 'BaseEventLoop.shutdown_asyncgens' was never 
awaited
Task was destroyed but it is pending!
task: >
```

here's a live demo on github actions: 
https://github.com/graingert/asyncio-backport/runs/3380502247#step:5:90

--
components: asyncio
messages: 399969
nosy: asvetlov, graingert, yselivanov
priority: normal
severity: normal
status: open
title: asyncio.create_task weakrefset race condition
versions: Python 3.8, Python 3.9

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



[issue44830] Broken Mozilla devguide link in "Dealing with Bugs" doc section

2021-08-18 Thread Thomas Grainger


Thomas Grainger  added the comment:

Depends on the redirect type they create. If it's temporary we should keep
the same URL, if it's permanent or otherwise has bookmark updating
semantics we should update the URL to follow the redirect

On Wed, 18 Aug 2021, 21:40 Jack DeVries,  wrote:

>
> Jack DeVries  added the comment:
>
> All right, consider the needle in the haystack officially found. This page
> has the same content as the missing page:
>
> https://bugzilla.mozilla.org/page.cgi?id=bug-writing.html
>
> Thank you @buhtz for opening an issue with Mozilla; they are eventually
> going to deploy a redirect to the link above from the old link:
> https://github.com/mdn/content/issues/8036
>
> So, we could go ahead and insert the link above which contains the same
> content as before. Or, we can keep the call open for a new document. What
> does everyone think?
>
> --
>
> ___
> Python tracker 
> <https://bugs.python.org/issue44830>
> ___
>

--

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



[issue44830] Broken Mozilla devguide link in "Dealing with Bugs" doc section

2021-08-16 Thread Thomas Grainger


Thomas Grainger  added the comment:

It looks like it got archived here 
https://github.com/mdn/archived-content/blob/main/files/en-us/mozilla/qa/bug_writing_guidelines/index.html

--
nosy: +graingert

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



[issue44928] async generator missing unawaited coroutine warning

2021-08-16 Thread Thomas Grainger


New submission from Thomas Grainger :

demo program:

```
def test_async_fn():
async def async_fn():
pass

async_fn()


def test_async_gen_fn():
async def agen_fn():
yield

agen_fn().aclose()
agen_fn().asend(None)

test_async_fn()
test_async_gen_fn()
```

output:

```
/home/graingert/projects/anyio/foo.py:5: RuntimeWarning: coroutine 
'test_async_fn..async_fn' was never awaited
  async_fn()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
```

expected:


```
/home/graingert/projects/anyio/foo.py:5: RuntimeWarning: coroutine 
'test_async_fn..async_fn' was never awaited
  async_fn()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
/home/graingert/projects/anyio/foo.py:12: RuntimeWarning: coroutine 
'' was never awaited
  agen_fn().aclose()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
/home/graingert/projects/anyio/foo.py:13: RuntimeWarning: coroutine 
'' was never awaited
  agen_fn().asend(None)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
```

--
components: Interpreter Core
messages: 399684
nosy: graingert
priority: normal
severity: normal
status: open
title: async generator missing unawaited coroutine warning
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 
3.9

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



[issue44908] recommend httpx as well as requests in http.client/urllib.request docs

2021-08-13 Thread Thomas Grainger


New submission from Thomas Grainger :

HTTPX is a fully featured HTTP client for Python 3, which provides sync and 
async APIs, and support for both HTTP/1.1 and HTTP/2.

It's also broadly compatible and inspired by the requests API: 
https://github.com/encode/httpx/blob/master/docs/compatibility.md#requests-compatibility-guide


Currently the project is looking to get a link from the docs to 
https://www.python-httpx.org/

here's the upstream issue https://github.com/encode/httpx/issues/1772

--
assignee: docs@python
components: Documentation
messages: 399494
nosy: docs@python, graingert
priority: normal
severity: normal
status: open
title: recommend httpx as well as requests in http.client/urllib.request docs
versions: Python 3.10, Python 3.11

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



[issue44070] __file__ is now fully qualified in 3.8 and 3.9

2021-07-28 Thread Thomas Grainger


Thomas Grainger  added the comment:

Yep that's the fix I went for in the end 
https://github.com/twisted/twisted/pull/1628/files#diff-8110fe13865c1f305bb999e82cd7514b2e7269f41087bd7ef39c3d6de508R105

--

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



[issue37715] 2to3 set default encoding

2021-07-27 Thread Thomas Grainger


Thomas Grainger  added the comment:

lib2to3 is deprecated and is pending removal, so I think this can be closed

--
nosy: +graingert

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



[issue43468] functools.cached_property incorrectly locks the entire descriptor on class instead of per-instance locking

2021-07-27 Thread Thomas Grainger


Thomas Grainger  added the comment:

> using a per-descriptor `WeakKeyDictionary` to map the instance to locks 
> (which would of course not work - is there any way to map unhashable 
> instances weakly?)

there's an issue for that too: https://bugs.python.org/issue44140

--

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



[issue43468] functools.cached_property incorrectly locks the entire descriptor on class instead of per-instance locking

2021-07-27 Thread Thomas Grainger


Thomas Grainger  added the comment:

how about deprecating the functools.cached_property?

--
nosy: +graingert

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



[issue44686] use pkgutil.resolve_name in unittest.mock

2021-07-20 Thread Thomas Grainger


New submission from Thomas Grainger :

per https://bugs.python.org/issue12915 pkgutil.resolve_name was added for use 
in mock and other stdlib modules:

> pydoc has locate and resolve, packaging has util.resolve_name, unittest has 
> something else, etc.

--
messages: 397905
nosy: graingert
priority: normal
pull_requests: 25814
severity: normal
status: open
title: use pkgutil.resolve_name in unittest.mock
versions: Python 3.11

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



[issue44070] __file__ is now fully qualified in 3.8 and 3.9

2021-07-15 Thread Thomas Grainger

Thomas Grainger  added the comment:

hello, just chiming in to let you know that this broke CI on twisted: 
https://github.com/twisted/twisted/pull/1628/ (As above for Chalice, I think 
this didn't actually break the framework itself, just the tests for the 
framework. )

do you know what the correct usage of importlib.util.spec_from_file_location is 
to match importlib.import_module ?


I have a tree like this:

.
└── mypkg
├── demo.py
├── __init__.py
└── __pycache__
├── __init__.cpython-38.pyc
└── __init__.cpython-39.pyc

2 directories, 4 files


but I'm not sure how to get a spec for ./mypkg/demo.py:


Python 3.9.6 (default, Jul  3 2021, 16:40:50) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python39.zip', '/usr/lib/python3.9', 
'/usr/lib/python3.9/lib-dynload', '/usr/local/lib/python3.9/dist-packages', 
'/usr/lib/python3/dist-packages']
>>> import os
>>> os.getcwd()
'/home/graingert/projects/syspath-tests'
>>> import importlib.util
>>> importlib.util.spec_from_file_location(name="mypkg.demo", 
>>> location="mypkg/demo.py")
ModuleSpec(name='mypkg.demo', 
loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fc94644bfd0>, 
origin='mypkg/demo.py')
>>> import mypkg.demo
>>> mypkg.demo.__spec__
ModuleSpec(name='mypkg.demo', 
loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fc94645a160>, 
origin='/home/graingert/projects/syspath-tests/mypkg/demo.py')
>>>

--
nosy: +graingert

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



[issue44611] CPython uses deprecated randomness API

2021-07-12 Thread Thomas Grainger


Thomas Grainger  added the comment:

https://docs.microsoft.com/en-us/windows/win32/seccng/cng-portal ?

--
nosy: +graingert

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



[issue44428] _ProactorBasePipeTransport.abort() after _ProactorBasePipeTransport.close() does not cancel writes

2021-07-12 Thread Thomas Grainger


Change by Thomas Grainger :


--
nosy: +lukasz.langa

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



[issue44566] StopIteration subclass raised in body of 'with' statement suppressed

2021-07-05 Thread Thomas Grainger


Change by Thomas Grainger :


--
keywords: +patch
pull_requests: +25590
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/27024

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



[issue44566] StopIteration subclass raised in body of 'with' statement suppressed

2021-07-05 Thread Thomas Grainger


Thomas Grainger  added the comment:

This is the output:

```
Traceback (most recent call last):
  File "/home/graingert/projects/close.py", line 5, in foo
yield
  File "/home/graingert/projects/close.py", line 12, in 
raise StartIrritation
__main__.StartIrritation

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/graingert/projects/close.py", line 11, in 
with foo():
  File "/usr/lib/python3.10/contextlib.py", line 151, in __exit__
self.gen.throw(type, value, traceback)
RuntimeError: generator raised StopIteration
```


Note that this was fixed in @contextlib.asynccontextmanager
```
import asyncio
import contextlib

@contextlib.asynccontextmanager
async def foo():
yield

class StartIrritation(StopIteration):
pass


async def amain():
try:
async with foo():
raise StartIrritation
except StartIrritation:
print("good")
except RuntimeError:
print("bad")

asyncio.run(amain())
```

--

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



[issue1462485] StopIteration raised in body of 'with' statement suppressed

2021-07-05 Thread Thomas Grainger


Thomas Grainger  added the comment:

apologies I meant to post this on a new ticket

--

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



[issue44566] StopIteration subclass raised in body of 'with' statement suppressed

2021-07-05 Thread Thomas Grainger


New submission from Thomas Grainger :

https://bugs.python.org/issue1462485


import contextlib

@contextlib.contextmanager
def foo():
yield

class StartIrritation(StopIteration):
pass


with foo():
raise StartIrritation

--
messages: 396979
nosy: graingert, ncoghlan, yselivanov
priority: normal
severity: normal
status: open
title: StopIteration subclass raised in body of 'with' statement suppressed
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 
3.9

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



[issue1462485] StopIteration raised in body of 'with' statement suppressed

2021-07-05 Thread Thomas Grainger


Thomas Grainger  added the comment:

```
import contextlib

@contextlib.contextmanager
def foo():
yield

class StartIrritation(StopIteration):
pass


with foo():
raise StartIrritation
```

--
nosy: +graingert

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



[issue44428] _ProactorBasePipeTransport.abort() after _ProactorBasePipeTransport.close() does not cancel writes

2021-06-26 Thread Thomas Grainger


Thomas Grainger  added the comment:

nosying the author of the selector_events fix

--

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



[issue44428] _ProactorBasePipeTransport.abort() after _ProactorBasePipeTransport.close() does not cancel writes

2021-06-26 Thread Thomas Grainger


Change by Thomas Grainger :


--
nosy: +gvanrossum

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



[issue33408] Enable AF_UNIX support in Windows

2021-06-26 Thread Thomas Grainger


Change by Thomas Grainger :


--
nosy: +graingert

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



[issue44446] linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension

2021-06-17 Thread Thomas Grainger


Change by Thomas Grainger :


--
nosy: +nedbat

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



[issue44446] linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension

2021-06-17 Thread Thomas Grainger


Change by Thomas Grainger :


--
nosy: +Mark.Shannon -nedbat

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



[issue44446] linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension

2021-06-17 Thread Thomas Grainger


New submission from Thomas Grainger :

demo:

import traceback
import io

async def foo():
yield 1
traceback.print_stack(file=io.StringIO())
yield 2

async def bar():
return [chunk async for chunk in foo()]


next(bar().__await__(), None)
print("working!")


Traceback (most recent call last):
  File "/home/graingert/projects/anyio/foo.py", line 13, in 
next(bar().__await__(), None)
  File "/home/graingert/projects/anyio/foo.py", line 10, in bar
return [chunk async for chunk in foo()]
  File "/home/graingert/projects/anyio/foo.py", line -1, in 
  File "/home/graingert/projects/anyio/foo.py", line 6, in foo
traceback.print_stack(file=io.StringIO())
  File "/usr/lib/python3.10/traceback.py", line 203, in print_stack
print_list(extract_stack(f, limit=limit), file=file)
  File "/usr/lib/python3.10/traceback.py", line 224, in extract_stack
stack = StackSummary.extract(walk_stack(f), limit=limit)
  File "/usr/lib/python3.10/traceback.py", line 379, in extract
f.line
  File "/usr/lib/python3.10/traceback.py", line 301, in line
self._line = linecache.getline(self.filename, self.lineno).strip()
  File "/usr/lib/python3.10/linecache.py", line 31, in getline
if 1 <= lineno <= len(lines):
TypeError: '<=' not supported between instances of 'int' and 'NoneType'

--
messages: 396014
nosy: graingert
priority: normal
severity: normal
status: open
title: linecache.getline TypeError when formatting tracebacks in stacks 
containing an async list comprehension
versions: Python 3.10

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



[issue44428] _ProactorBasePipeTransport.abort() after _ProactorBasePipeTransport.close() does not cancel writes

2021-06-15 Thread Thomas Grainger


New submission from Thomas Grainger :

demo program:

import asyncio
import socket
import threading

async def amain():
family = socket.AddressFamily.AF_INET
sock = socket.socket(family, socket.SOCK_STREAM)
sock.settimeout(1)
sock.bind(('localhost', 0))
sock.listen()
host, port = sock.getsockname()[:2]

event = threading.Event()

def serve():
client, _ = sock.accept()
with client:
client.recv(1)
event.wait()

t = threading.Thread(target=serve, daemon=True)
t.start()

reader, writer = await asyncio.open_connection(host=host, port=port)
try:
while True:
writer.write(b"\x00" * 4096 * 682 * 2)
await asyncio.wait_for(writer.drain(), 2)
print("wrote")
except asyncio.TimeoutError:
print("timed out")

writer.close()
await asyncio.sleep(0)
writer.transport.abort()
print("waiting close")
await writer.wait_closed()  # never finishes on ProactorEventLoop
print("closed")
event.set()
t.join()

asyncio.run(amain())

it looks like it was fixed for the selector eventloop in 
https://github.com/python/cpython/commit/2546a177650264205e8a52b6836bc5b8c48bf085

but not for the proactor 
https://github.com/python/cpython/blame/8fe57aacc7bf9d9af84803b69dbb1d66597934c6/Lib/asyncio/proactor_events.py#L140

--
components: asyncio
messages: 395896
nosy: asvetlov, graingert, yselivanov
priority: normal
severity: normal
status: open
title: _ProactorBasePipeTransport.abort() after 
_ProactorBasePipeTransport.close() does not cancel writes
versions: Python 3.10, Python 3.8, Python 3.9

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



[issue44362] improve documentation of SSL deprecations

2021-06-10 Thread Thomas Grainger


Thomas Grainger  added the comment:

> Would you like me to submit a PR for this simple patch?
> 
> https://github.com/jdevries3133/cpython/commit/42d9bd7f97f03b49d4fc89780616704998492ac1


TLS_PROTOCOL_CLIENT and TLS_PROTOCOL_SERVER are defined in terms of the 
deprecated TLS_PROTOCOL, so now this makes the definition circular

--

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



[issue44354] ssl deprecation warnings erganomics

2021-06-10 Thread Thomas Grainger


Thomas Grainger  added the comment:

there should still be a deprecation warning so that 3.12 can raise 
AttributeError

--

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



[issue44354] ssl deprecation warnings erganomics

2021-06-10 Thread Thomas Grainger


Thomas Grainger  added the comment:

it looks like OP_NO_SSLv2 and OP_NO_SSLv3 are not raising a DeprecationWarning


```
python310 -W error
Python 3.10.0b2 (default, Jun  2 2021, 00:22:18) [GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> ssl.SSLContext(ssl.PROTOCOL_TLS)
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.10/ssl.py", line 501, in __new__
self = _SSLContext.__new__(cls, protocol)
DeprecationWarning: ssl module: PROTOCOL_TLS is deprecated
>>> ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)

>>> c = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
>>> c.options |= ssl.OP_NO_SSLv2  # no deprecation warning!?
>>> c.options |= ssl.OP_NO_SSLv3  # no deprecation warning!?
>>> c.options |= ssl.OP_NO_TLSv1
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.10/ssl.py", line 621, in options
super(SSLContext, SSLContext).options.__set__(self, value)
DeprecationWarning: ssl module: Setting OP_NO_SSL* or SSL_NO_TLS* options is 
deprecated is deprecated
```

--

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



[issue44362] improve documentation of SSL deprecations

2021-06-09 Thread Thomas Grainger


Thomas Grainger  added the comment:

It's also confusing that other not deprecated flags are described in terms of 
this deprecated flag. These will need rewriting when the deprecated flag is 
removed

--

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



[issue44362] improve documentation of SSL deprecations

2021-06-09 Thread Thomas Grainger


New submission from Thomas Grainger :

> I can see in the 3.10 release notes, that ssl.PROTOCOL_TLS becomes 
> deprecated. Is there any further context explaining why, and what the 
> preferred usage is instead, so that I (and anyone else) can understand this a 
> bit more thoroughly?

https://github.com/encode/httpx/issues/1670#issuecomment-857509311

--
messages: 395398
nosy: alex, christian.heimes, dstufft, graingert, janssen
priority: normal
severity: normal
status: open
title: improve documentation of SSL deprecations
versions: Python 3.10, Python 3.11

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



[issue44354] ssl deprecation warnings erganomics

2021-06-08 Thread Thomas Grainger


Thomas Grainger  added the comment:

the "ssl module:" part of the warning message, I think, is redundant as it 
should be defined in the 
https://docs.python.org/3/library/warnings.html#warnings.warn_explicit module 
kwarg

--

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



[issue44354] ssl deprecation warnings erganomics

2021-06-08 Thread Thomas Grainger


New submission from Thomas Grainger :

The ssl module OP_NO_* deprecation warning message is slightly wrong: The error 
message prints out "is deprecated is deprecated" because of an earlier format 
template

There's a colon in the warning message `ssl module:` and that makes it 
difficult to use in simplefilter

The NPN deprecation warnning raises a UserWarning instead of DeprecationWarning

see also UserWarning: ssl module: NPN is deprecated, use ALPN instead

--
messages: 395362
nosy: alex, christian.heimes, dstufft, graingert, janssen
priority: normal
pull_requests: 25197
severity: normal
status: open
title: ssl deprecation warnings erganomics
versions: Python 3.10, Python 3.11

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



[issue44306] asyncio.from_thread

2021-06-03 Thread Thomas Grainger


Thomas Grainger  added the comment:

"""High-level support for working with threads in asyncio"""

import functools
import contextvars

from . import events
from . import tasks


__all__ = "to_thread", "from_thread"


class _Local(threading.local):
loop = None


_local = _Local()


def _with_loop(loop, func, /, *args, **kwargs):
_loop.loop = loop
try:
return func(*args, **kwargs)
finally:
_loop.loop = None


async def to_thread(func, /, *args, **kwargs):
"""Asynchronously run function *func* in a separate thread.

Any *args and **kwargs supplied for this function are directly passed
to *func*. Also, the current :class:`contextvars.Context` is propogated,
allowing context variables from the main thread to be accessed in the
separate thread.

Return a coroutine that can be awaited to get the eventual result of *func*.
"""
loop = events.get_running_loop()
ctx = contextvars.copy_context()
func_call = functools.partial(_with_loop, loop, ctx.run, func, *args, 
**kwargs)
return await loop.run_in_executor(None, func_call)


def _create_task(async_func, /, *args, **kwargs):
return events.create_task(async_func(*args, **kwargs))


async def _with_context(ctx, async_func, /, *args, **kwargs):
return await ctx.run(_create_task, async_func, *args, **kwargs)


def from_thread(async_func, /, *args, **kwargs):
"""Synchronously run function *async_func* in the event loop thread.

Any *args and **kwargs supplied for this function are directly passed
to *func*. Also, the current :class:`contextvars.Context` is propogated,
allowing context variables from the main thread to be accessed in the
separate thread.

Return a concurrent.futures.Future to wait for the result from the event
loop thread.
"""
loop = _loop.loop
if loop is None:
raise RuntimeError(
"asyncio.from_thread can only be run in a thread started by "
"asyncio.to_thread"
)

ctx = contextvars.copy_context()
return tasks.run_coroutine_threadsafe(loop, _with_context(ctx, async_func, 
*args, **kwargs))

--

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



[issue44306] asyncio.from_thread

2021-06-03 Thread Thomas Grainger


New submission from Thomas Grainger :

create a asyncio.from_thread shortcut to run async functions from a thread 
started with asyncio.to_thread


```
def from_thread(async_func, /, *args, **kwargs):
"""Synchronously run function *async_func* in the event loop thread.

Any *args and **kwargs supplied for this function are directly passed
to *func*. Also, the current :class:`contextvars.Context` is propogated,
allowing context variables from the main thread to be accessed in the
separate thread.

Return a concurrent.futures.Future to wait for the result from the event
loop thread.
```

--
components: asyncio
messages: 395054
nosy: asvetlov, graingert, yselivanov
priority: normal
severity: normal
status: open
title: asyncio.from_thread

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



[issue40720] accessing mmap of file that is overwritten causes bus error

2021-03-09 Thread Thomas Grainger


Thomas Grainger  added the comment:

I can confirm this happens on py3.5-3.10

```
import mmap
import pathlib
import tempfile


def main():
with tempfile.TemporaryDirectory() as tmp:
tmp_path = pathlib.Path(tmp)
path = tmp_path / "eg"

path.write_bytes(b"Hello, World!")

with path.open("rb") as rf:
mm = mmap.mmap(rf.fileno(), 0, mmap.MAP_SHARED, mmap.PROT_READ)
path.write_bytes(b"")
bytes(mm)

if __name__ == "__main__":
main()
```

--
nosy: +graingert
versions: +Python 3.10, Python 3.6, Python 3.7, Python 3.9

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



[issue43216] Removal of @asyncio.coroutine in Python 3.10

2021-03-06 Thread Thomas Grainger


Change by Thomas Grainger :


--
nosy: +graingert

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



[issue37771] No equivalent of `inspect.getcoroutinestate` for PyAsyncGenASend instances

2021-03-06 Thread Thomas Grainger


Change by Thomas Grainger :


--
nosy: +alex.gronholm, graingert

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



[issue41602] Python doesn't exit with proper resultcode on SIGINT in runpy (pymain_run_module)

2020-09-24 Thread Thomas Grainger


Change by Thomas Grainger :


--
pull_requests: +21438
pull_request: https://github.com/python/cpython/pull/22398

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



[issue41602] Python doesn't exit with proper resultcode on SIGINT in runpy (pymain_run_module)

2020-09-16 Thread Thomas Grainger


Thomas Grainger  added the comment:

nice the tests pass with that fix

--

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



[issue41602] Python doesn't exit with proper resultcode on SIGINT in runpy (pymain_run_module)

2020-09-16 Thread Thomas Grainger


Thomas Grainger  added the comment:

I pushed that patch

--
versions:  -Python 3.10

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



[issue41602] Python doesn't exit with proper resultcode on SIGINT in runpy (pymain_run_module)

2020-09-16 Thread Thomas Grainger


Thomas Grainger  added the comment:

I'm assuming _Py_UnhandledKeyboardInterrupt is getting incorrectly cleared 
somewhere in here

https://github.com/python/cpython/blob/fc23a9483ef0d7c98bea9f82392377d0b6ef7b18/Modules/main.c#L291-L300

Py_DECREF(runpy);
Py_DECREF(runmodule);
Py_DECREF(module);
Py_DECREF(runargs);
if (result == NULL) {
return pymain_exit_err_print();
}
Py_DECREF(result);
return 0;
}

--

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



[issue41602] Python doesn't exit with proper resultcode on SIGINT in runpy (pymain_run_module)

2020-09-16 Thread Thomas Grainger


Thomas Grainger  added the comment:

> Okay, I got it. Now my next question. What do you mean by "I've eliminated 
> runpy" and various other remarks along those lines?

I can use `runpy._run_module_as_main` from another Python entry, eg -c and get 
the correct `-2`

>>> subprocess.run(["python3", "-c", 
>>> "__import__('runpy')._run_module_as_main('spam')"])
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.8/runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 86, in _run_code
exec(code, run_globals)
  File "/home/graingert/projects/osirium-main/spam.py", line 1, in 
raise KeyboardInterrupt
KeyboardInterrupt
CompletedProcess(args=['python3', '-c', 
"__import__('runpy')._run_module_as_main('spam')"], returncode=-2)


> Have you actually identified the root cause of the problem? What's your 
> suggested fix (without test framework).

No I don't have a fix

--

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



[issue41602] Python doesn't exit with proper resultcode on SIGINT in runpy (pymain_run_module)

2020-09-16 Thread Thomas Grainger


Thomas Grainger  added the comment:

The return code of python on linux when the program is ended with a 
KeyboardInterrupt should be -2, this works in most cases - except when called 
via "python -m"


Does this repl help?

Python 3.8.2 (default, Jul 16 2020, 14:00:26) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pathlib, subprocess
>>> pathlib.Path("spam.py").write_text("raise KeyboardInterrupt")
23
>>> subprocess.run(["python3", "spam.py"])
Traceback (most recent call last):
  File "spam.py", line 1, in 
raise KeyboardInterrupt
KeyboardInterrupt
CompletedProcess(args=['python3', 'spam.py'], returncode=-2)
>>> subprocess.run(["python3", "-m", "spam"])
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 86, in _run_code
exec(code, run_globals)
  File "/home/graingert/projects/spam.py", line 1, in 
raise KeyboardInterrupt
KeyboardInterrupt
CompletedProcess(args=['python3', '-m', 'spam'], returncode=1)
>>>

--

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



[issue41602] Python doesn't exit with proper resultcode on SIGINT in runpy (pymain_run_module)

2020-09-16 Thread Thomas Grainger


Thomas Grainger  added the comment:

adding `__main__` owners to nosy

--
nosy: +gvanrossum

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



[issue41676] asyncio.Event.wait broken link from asyncio.Event

2020-08-31 Thread Thomas Grainger


Change by Thomas Grainger :


--
keywords: +patch
pull_requests: +21129
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/22029

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



[issue41676] asyncio.Event.wait broken link from asyncio.Event

2020-08-31 Thread Thomas Grainger


New submission from Thomas Grainger :

https://docs.python.org/dev/library/asyncio-sync.html#asyncio.Event links to 
https://docs.python.org/dev/library/asyncio-task.html#asyncio.wait instead of 
https://docs.python.org/dev/library/asyncio-sync.html#asyncio.Event.wait

--
assignee: docs@python
components: Documentation
messages: 376153
nosy: docs@python, graingert
priority: normal
severity: normal
status: open
title: asyncio.Event.wait broken link from asyncio.Event
versions: Python 3.10, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 
3.9

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



[issue41643] make shutil.make_archive always accept pathlib objects

2020-08-26 Thread Thomas Grainger


Change by Thomas Grainger :


--
keywords: +patch
pull_requests: +21072
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21962

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



[issue41643] make shutil.make_archive always accepts pathlib objects

2020-08-26 Thread Thomas Grainger


New submission from Thomas Grainger :

>>> shutil.make_archive(pathlib.Path("./foo"), root_dir=pathlib.Path("./foo"), 
>>> format="zip")
'/home/graingert/projects/ham/foo.zip'


>>> shutil.make_archive(pathlib.Path("./foo"), root_dir=None, format="zip")
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.8/shutil.py", line 1045, in make_archive
filename = func(base_name, base_dir, **kwargs)
  File "/usr/lib/python3.8/shutil.py", line 912, in _make_zipfile
zip_filename = base_name + ".zip"
TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str'

see also https://bugs.python.org/issue23241

--
components: Library (Lib)
messages: 375927
nosy: graingert
priority: normal
severity: normal
status: open
title: make shutil.make_archive always accepts pathlib objects
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8

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



[issue41643] make shutil.make_archive always accept pathlib objects

2020-08-26 Thread Thomas Grainger


Change by Thomas Grainger :


--
title: make shutil.make_archive always accepts pathlib objects -> make 
shutil.make_archive always accept pathlib objects

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



  1   2   >