Skip to content

CPython 3.13 Compat and Asyncore Removal #1244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions cassandra/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ def _try_libev_import():
except DependencyException as e:
return (None, e)

def _try_asyncore_import():
def _try_asyncio_import():
try:
from cassandra.io.asyncorereactor import AsyncoreConnection
return (AsyncoreConnection,None)
from cassandra.io.asyncioreactor import AsyncioConnection
return (AsyncioConnection,None)
except DependencyException as e:
return (None, e)

Expand All @@ -167,7 +167,7 @@ def _connection_reduce_fn(val,import_fn):

log = logging.getLogger(__name__)

conn_fns = (_try_gevent_import, _try_eventlet_import, _try_libev_import, _try_asyncore_import)
conn_fns = (_try_gevent_import, _try_eventlet_import, _try_libev_import, _try_asyncio_import)
(conn_class, excs) = reduce(_connection_reduce_fn, conn_fns, (None,[]))
if not conn_class:
raise DependencyException("Unable to load a default connection class", excs)
Expand Down Expand Up @@ -875,15 +875,15 @@ def default_retry_policy(self, policy):
This determines what event loop system will be used for managing
I/O with Cassandra. These are the current options:

* :class:`cassandra.io.asyncorereactor.AsyncoreConnection`
* :class:`cassandra.io.asyncioreactor.AsyncioConnection`
* :class:`cassandra.io.libevreactor.LibevConnection`
* :class:`cassandra.io.eventletreactor.EventletConnection` (requires monkey-patching - see doc for details)
* :class:`cassandra.io.geventreactor.GeventConnection` (requires monkey-patching - see doc for details)
* :class:`cassandra.io.twistedreactor.TwistedConnection`
* EXPERIMENTAL: :class:`cassandra.io.asyncioreactor.AsyncioConnection`

By default, ``AsyncoreConnection`` will be used, which uses
the ``asyncore`` module in the Python standard library.
By default, ``AsyncioConnection`` will be used, which uses
the ``asyncio`` module in the Python standard library.

If ``libev`` is installed, ``LibevConnection`` will be used instead.

Expand Down
5 changes: 5 additions & 0 deletions cassandra/io/libevwrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,14 @@ initlibevwrapper(void)
if (PyModule_AddObject(module, "Timer", (PyObject *)&libevwrapper_TimerType) == -1)
INITERROR;

#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 7
// Since CPython 3.7, `Py_Initialize()` routing always initializes GIL.
// Routine `PyEval_ThreadsInitialized()` has been deprecated in CPython 3.7
// and completely removed in CPython 3.13.
if (!PyEval_ThreadsInitialized()) {
PyEval_InitThreads();
}
#endif

#if PY_MAJOR_VERSION >= 3
return module;
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/long/test_ipv6.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ccmlib import common

from cassandra.cluster import NoHostAvailable
from cassandra.io.asyncorereactor import AsyncoreConnection
from cassandra.io.asyncioreactor import AsyncioConnection

from tests import is_monkey_patched
from tests.integration import use_cluster, remove_cluster, TestCluster
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/io/test_asyncioreactor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
AsyncioConnection, ASYNCIO_AVAILABLE = None, False
try:
from cassandra.io.asyncioreactor import AsyncioConnection
import asynctest
ASYNCIO_AVAILABLE = True
except (ImportError, SyntaxError):
AsyncioConnection = None
Expand All @@ -11,6 +10,7 @@
from tests.unit.io.utils import TimerCallback, TimerTestMixin

from unittest.mock import patch
from unittest.mock import AsyncMock

import unittest
import time
Expand Down Expand Up @@ -56,7 +56,7 @@ def setUp(self):
socket_patcher.start()

old_selector = AsyncioConnection._loop._selector
AsyncioConnection._loop._selector = asynctest.TestSelector()
AsyncioConnection._loop._selector = AsyncMock()

def reset_selector():
AsyncioConnection._loop._selector = old_selector
Expand Down