Skip to content

Commit 6d08a73

Browse files
committed
1
1 parent 22ca7f2 commit 6d08a73

16 files changed

+37
-24
lines changed

cassandra/cluster.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103

104104
try:
105105
from cassandra.io.eventletreactor import EventletConnection
106-
except (ImportError, AttributeError):
106+
except DependencyException:
107107
# AttributeError was add for handling python 3.12 https://github.com/eventlet/eventlet/issues/812
108108
# TODO: remove it when eventlet issue would be fixed
109109
EventletConnection = None
@@ -153,11 +153,13 @@ def _is_gevent_monkey_patched():
153153

154154

155155
def _try_eventlet_import():
156-
if _is_eventlet_monkey_patched():
156+
try:
157157
from cassandra.io.eventletreactor import EventletConnection
158-
return (EventletConnection,None)
159-
else:
160-
return (None,None)
158+
except DependencyException as e:
159+
return None, e
160+
if _is_eventlet_monkey_patched():
161+
return EventletConnection, None
162+
return None, DependencyException("eventlet is not patched")
161163

162164
def _try_libev_import():
163165
try:
@@ -209,7 +211,7 @@ def get_default_connection_class():
209211
conn, exc = try_fn()
210212
if conn is not None:
211213
return conn, None
212-
else:
214+
if exc:
213215
excs.append(exc)
214216
return None, tuple(excs)
215217

cassandra/io/asyncorereactor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
from cassandra import DependencyException
3434
try:
3535
import asyncore
36-
except ModuleNotFoundError:
36+
except ModuleNotFoundError as e:
3737
raise DependencyException(
3838
"Unable to import asyncore module. Note that this module has been removed in Python 3.12 "
3939
"so when using the driver with this version (or anything newer) you will need to use one of the "
40-
"other event loop implementations."
40+
"other event loop implementations. Exception: %s" % str(e)
4141
)
4242

4343
from cassandra.connection import Connection, ConnectionShutdown, NONBLOCKING, Timer, TimerManager

cassandra/io/eventletreactor.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,20 @@
1515

1616
# Originally derived from MagnetoDB source:
1717
# https://github.com/stackforge/magnetodb/blob/2015.1.0b1/magnetodb/common/cassandra/io/eventletreactor.py
18-
import eventlet
19-
from eventlet.green import socket
20-
from eventlet.queue import Queue
21-
from greenlet import GreenletExit
18+
from cassandra import DependencyException
19+
20+
try:
21+
import eventlet
22+
from eventlet.green import socket
23+
from eventlet.queue import Queue
24+
except (ModuleNotFoundError, ImportError, AttributeError):
25+
raise DependencyException("Unable to import eventlet module. Try to install it via `pip install eventlet`")
26+
27+
try:
28+
from greenlet import GreenletExit
29+
except (ModuleNotFoundError, ImportError, AttributeError):
30+
raise DependencyException("Unable to import greenlet module. Try to install it via `pip install greenlet`")
31+
2232
import logging
2333
from threading import Event
2434
import time

tests/integration/advanced/test_cont_paging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import time
2626

2727
from cassandra.cluster import ExecutionProfile, ContinuousPagingOptions
28-
from cassandra.concurrent import execute_concurrent
28+
from cassandra.concurrent_executor import execute_concurrent
2929
from cassandra.query import SimpleStatement
3030

3131

tests/integration/cqlengine/query/test_named.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from cassandra.cqlengine.named import NamedKeyspace
2020
from cassandra.cqlengine.operators import EqualsOperator, GreaterThanOrEqualOperator
2121
from cassandra.cqlengine.query import ResultObject
22-
from cassandra.concurrent import execute_concurrent_with_args
22+
from cassandra.concurrent_executor import execute_concurrent_with_args
2323
from cassandra.cqlengine import models
2424

2525
from tests.integration.cqlengine import setup_connection, execute_count

tests/integration/long/test_failure_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
FunctionFailure, ProtocolVersion,
2727
)
2828
from cassandra.cluster import ExecutionProfile, EXEC_PROFILE_DEFAULT
29-
from cassandra.concurrent import execute_concurrent_with_args
29+
from cassandra.concurrent_executor import execute_concurrent_with_args
3030
from cassandra.query import SimpleStatement
3131
from tests.integration import (
3232
use_singledc, PROTOCOL_VERSION, get_cluster, setup_keyspace, remove_cluster,

tests/integration/long/test_loadbalancingpolicies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from cassandra import ConsistencyLevel, Unavailable, OperationTimedOut, ReadTimeout, ReadFailure, \
2222
WriteTimeout, WriteFailure
2323
from cassandra.cluster import NoHostAvailable, ExecutionProfile, EXEC_PROFILE_DEFAULT
24-
from cassandra.concurrent import execute_concurrent_with_args
24+
from cassandra.concurrent_executor import execute_concurrent_with_args
2525
from cassandra.metadata import murmur3
2626
from cassandra.policies import (
2727
RoundRobinPolicy, DCAwareRoundRobinPolicy,

tests/integration/standard/test_cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import cassandra
2929
from cassandra.cluster import NoHostAvailable, ExecutionProfile, EXEC_PROFILE_DEFAULT, ControlConnection, Cluster
30-
from cassandra.concurrent import execute_concurrent
30+
from cassandra.concurrent_executor import execute_concurrent
3131
from cassandra.policies import (RoundRobinPolicy, ExponentialReconnectionPolicy,
3232
RetryPolicy, SimpleConvictionPolicy, HostDistance,
3333
AddressTranslator, TokenAwarePolicy, HostFilterPolicy)

tests/integration/standard/test_concurrent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from cassandra import InvalidRequest, ConsistencyLevel, ReadTimeout, WriteTimeout, OperationTimedOut, \
1919
ReadFailure, WriteFailure
2020
from cassandra.cluster import ExecutionProfile, EXEC_PROFILE_DEFAULT
21-
from cassandra.concurrent import execute_concurrent, execute_concurrent_with_args, ExecutionResult
21+
from cassandra.concurrent_executor import execute_concurrent, execute_concurrent_with_args, ExecutionResult
2222
from cassandra.policies import HostDistance
2323
from cassandra.query import dict_factory, tuple_factory, SimpleStatement
2424

0 commit comments

Comments
 (0)