Skip to content

Conversation

@sbdchd
Copy link
Contributor

@sbdchd sbdchd commented Dec 10, 2020

ThreadPoolExecutor assigns a queue.SimpleQueue to _work_queue in
it's __init__ method.

https://github.com/python/cpython/blob/7cf0aad96d1d20f07d7f0e374885f327c2d5ff27/Lib/concurrent/futures/thread.py#L144

_S = TypeVar("_S")

class ThreadPoolExecutor(Executor):
_work_queue: Any
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could use a better type, but I'm not sure what it should be

ThreadPoolExecutor assigns it queue.SimpleQueue so it could be that,
but it only uses a few methods so maybe a protocol would be better?

class _QueueLike(Protocol):
    def get(self, block: bool = ...) -> Any: ...
    def get_nowait(self) -> Any: ...
    def put(self, item: Any) -> None: ...

Or maybe just queue.Queue?

rel: https://github.com/python/cpython/blob/7cf0aad96d1d20f07d7f0e374885f327c2d5ff27/Lib/concurrent/futures/thread.py#L144
rel: https://github.com/python/cpython/blob/7cf0aad96d1d20f07d7f0e374885f327c2d5ff27/Lib/queue.py

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 3.6 it's actually a queue.Queue; haven't checked when the change was made. I think we should just use the concrete type that's present at runtime; it doesn't really make sense to introduce a custom protocol for a private field.

@JelleZijlstra JelleZijlstra merged commit 3d14016 into python:master Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants