Skip to content

Commit

Permalink
Remove tokio support (#7281) (#7282)
Browse files Browse the repository at this point in the history
Project has been archived and was last updated 6 years ago. It's dead.

(cherry picked from commit 0761da6)

<!-- Thank you for your contribution! -->

## What do these changes do?

<!-- Please give a short brief about these changes. -->

## Are there changes in behavior for the user?

<!-- Outline any notable behaviour for the end users. -->

## Related issue number

<!-- Are there any issues opened that will be resolved by merging this
change? -->

## Checklist

- [ ] I think the code is well written
- [ ] Unit tests for the changes exist
- [ ] Documentation reflects the changes
- [ ] If you provide code modification, please add yourself to
`CONTRIBUTORS.txt`
  * The format is &lt;Name&gt; &lt;Surname&gt;.
  * Please keep alphabetical order, the file is sorted by names.
- [ ] Add a new news fragment into the `CHANGES` folder
  * name it `<issue_id>.<type>` for example (588.bugfix)
* if you don't have an `issue_id` change it to the pr id after creating
the pr
  * ensure type is one of the following:
    * `.feature`: Signifying a new feature.
    * `.bugfix`: Signifying a bug fix.
    * `.doc`: Signifying a documentation improvement.
    * `.removal`: Signifying a deprecation or removal of public API.
* `.misc`: A ticket has been closed, but it is not of interest to users.
* Make sure to use full sentences with correct case and punctuation, for
example: "Fix issue with non-ascii contents in doctest text files."
  • Loading branch information
Dreamsorcerer authored May 13, 2023
1 parent bddf6c2 commit b2541b1
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 47 deletions.
3 changes: 0 additions & 3 deletions .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ ignore_missing_imports = True
[mypy-gunicorn.*]
ignore_missing_imports = True

[mypy-tokio]
ignore_missing_imports = True

[mypy-uvloop]
ignore_missing_imports = True

Expand Down
1 change: 1 addition & 0 deletions CHANGES/7281.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed support for unsupported ``tokio`` event loop -- by :user:`Dreamsorcerer`
12 changes: 2 additions & 10 deletions aiohttp/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
except ImportError: # pragma: no cover
uvloop = None

try:
import tokio
except ImportError: # pragma: no cover
tokio = None

AiohttpClient = Callable[[Union[Application, BaseTestServer]], Awaitable[TestClient]]


Expand All @@ -44,7 +39,7 @@ def pytest_addoption(parser): # type: ignore[no-untyped-def]
"--aiohttp-loop",
action="store",
default="pyloop",
help="run tests with specific loop: pyloop, uvloop, tokio or all",
help="run tests with specific loop: pyloop, uvloop or all",
)
parser.addoption(
"--aiohttp-enable-loop-debug",
Expand Down Expand Up @@ -198,11 +193,8 @@ def pytest_generate_tests(metafunc): # type: ignore[no-untyped-def]
if uvloop is not None: # pragma: no cover
avail_factories["uvloop"] = uvloop.EventLoopPolicy

if tokio is not None: # pragma: no cover
avail_factories["tokio"] = tokio.EventLoopPolicy

if loops == "all":
loops = "pyloop,uvloop?,tokio?"
loops = "pyloop,uvloop?"

factories = {} # type: ignore[var-annotated]
for name in loops.split(","):
Expand Down
18 changes: 1 addition & 17 deletions aiohttp/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
SSLContext = object # type: ignore[misc,assignment]


__all__ = ("GunicornWebWorker", "GunicornUVLoopWebWorker", "GunicornTokioWebWorker")
__all__ = ("GunicornWebWorker", "GunicornUVLoopWebWorker")


class GunicornWebWorker(base.Worker): # type: ignore[misc,no-any-unimported]
Expand Down Expand Up @@ -251,19 +251,3 @@ def init_process(self) -> None:
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

super().init_process()


class GunicornTokioWebWorker(GunicornWebWorker):
def init_process(self) -> None: # pragma: no cover
import tokio

# Close any existing event loop before setting a
# new policy.
asyncio.get_event_loop().close()

# Setup tokio policy, so that every
# asyncio.get_event_loop() will create an instance
# of tokio event loop.
asyncio.set_event_loop_policy(tokio.EventLoopPolicy())

super().init_process()
7 changes: 0 additions & 7 deletions tests/test_run_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,13 @@
HAS_IPV6 = False


# tokio event loop does not allow to override attributes
def skip_if_no_dict(loop):
if not hasattr(loop, "__dict__"):
pytest.skip("can not override loop attributes")


def skip_if_on_windows():
if platform.system() == "Windows":
pytest.skip("the test is not valid for Windows")


@pytest.fixture
def patched_loop(loop):
skip_if_no_dict(loop)
server = mock.Mock()
server.wait_closed = make_mocked_coro(None)
loop.create_server = make_mocked_coro(server)
Expand Down
10 changes: 0 additions & 10 deletions tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@
ACCEPTABLE_LOG_FORMAT = '%a "%{Referrer}i" %s'


# tokio event loop does not allow to override attributes
def skip_if_no_dict(loop):
if not hasattr(loop, "__dict__"):
pytest.skip("can not override loop attributes")


class BaseTestWorker:
def __init__(self):
self.servers = {}
Expand Down Expand Up @@ -202,8 +196,6 @@ def test__get_valid_log_format_exc(worker) -> None:


async def test__run_ok_parent_changed(worker, loop, aiohttp_unused_port) -> None:
skip_if_no_dict(loop)

worker.ppid = 0
worker.alive = True
sock = socket.socket()
Expand All @@ -223,8 +215,6 @@ async def test__run_ok_parent_changed(worker, loop, aiohttp_unused_port) -> None


async def test__run_exc(worker, loop, aiohttp_unused_port) -> None:
skip_if_no_dict(loop)

worker.ppid = os.getppid()
worker.alive = True
sock = socket.socket()
Expand Down

0 comments on commit b2541b1

Please sign in to comment.