The database works fine from the view code if I only import SimpleClient
within the same view file. This kind of implies that importing SimpleClient
(and therefore the python driver) in multiple places is what is breaking my
code.
Here is the cassandra stack trace when I set logging.basicConfig(level=
'DEBUG'). There was a lot of debug code here that I'm not including, which
basically showed that multiple connections were created before I ever
called my connect function. All of the code I attached is from loading the
view - multiple connections are already open, although when my request
comes in, the connection is closed immediately.
I've noticed that simply importing the SimpleClient() without running any
other code causes cassandra to generate a new transaction token.
I'm not entirely sure how to solve this, but I'll start by looking at
SQLalchemy or other pyramid code; I'm hoping that it's simply an issue of
scoping.
DEBUG:cassandra.pool:Host 127.0.0.1 is now marked up
DEBUG:cassandra.cluster:[control connection] Opening new connection to
127.0.0.1
DEBUG:cassandra.connection:Sending initial options message for new
connection (140149920838936) to 127.0.0.1
DEBUG:cassandra.io.asyncorereactor:Closing connection (140149920838936) to
127.0.0.1
DEBUG:cassandra.io.asyncorereactor:Closed socket to 127.0.0.1
WARNING:cassandra.cluster:[control connection] Error connecting to
127.0.0.1:
Traceback (most recent call last):
File
"/home/taylor/projects/tacle/env34/lib/python3.4/site-packages/cassandra/cluster.py",
line 1524, in _reconnect_internal
return self._try_connect(host)
File
"/home/taylor/projects/tacle/env34/lib/python3.4/site-packages/cassandra/cluster.py",
line 1541, in _try_connect
connection = self._cluster.connection_factory(host.address,
is_control_connection=True)
File
"/home/taylor/projects/tacle/env34/lib/python3.4/site-packages/cassandra/cluster.py",
line 503, in connection_factory
return self.connection_class.factory(address, *args, **kwargs)
File
"/home/taylor/projects/tacle/env34/lib/python3.4/site-packages/cassandra/io/asyncorereactor.py",
line 139, in factory
raise OperationTimedOut("Timed out creating connection")
cassandra.OperationTimedOut: errors=Timed out creating connection,
last_host=None
ERROR:cassandra.cluster:Control connection failed to connect, shutting down
Cluster:
Traceback (most recent call last):
File
"/home/taylor/projects/tacle/env34/lib/python3.4/site-packages/cassandra/cluster.py",
line 546, in connect
self.control_connection.connect()
File
"/home/taylor/projects/tacle/env34/lib/python3.4/site-packages/cassandra/cluster.py",
line 1498, in connect
self._set_new_connection(self._reconnect_internal())
File
"/home/taylor/projects/tacle/env34/lib/python3.4/site-packages/cassandra/cluster.py",
line 1533, in _reconnect_internal
raise NoHostAvailable("Unable to connect to any servers", errors)
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers',
{'127.0.0.1': OperationTimedOut('errors=Timed out creating connection,
last_host=None',)})
DEBUG:cassandra.cluster:Shutting down Cluster Scheduler
DEBUG:cassandra.cluster:Shutting down control connection
DEBUG:cassandra.cluster:Not executing scheduled task due to Scheduler
shutdown
On Saturday, June 7, 2014 1:25:24 AM UTC-4, SamuraiNinja007 wrote:
>
> I can connect to my database in __init__.py, but connecting to the
> database in a view function times out. I'm using the DataStax python
> driver. I get the same result if I create the connection somewhere else and
> import it, so I really doubt it's caused by a timeout due to initialising
> the connection.
>
> about to create client
> SimpleClient created
> Traceback (most recent call last):
> File
> "/home/taylor/projects/tacle/env34/lib/python3.4/site-packages/pyramid-1.5-py3.4.egg/pyramid/router.py",
>
> line 242, in __call__
> response = self.invoke_subrequest(request, use_tweens=True)
> File
> "/home/taylor/projects/tacle/env34/lib/python3.4/site-packages/pyramid-1.5-py3.4.egg/pyramid/router.py",
>
> line 217, in invoke_subrequest
> response = handle_request(request)
> File
> "/home/taylor/projects/tacle/env34/lib/python3.4/site-packages/pyramid-1.5-py3.4.egg/pyramid/tweens.py",
>
> line 21, in excview_tween
> response = handler(request)
> File
> "/home/taylor/projects/tacle/env34/lib/python3.4/site-packages/pyramid-1.5-py3.4.egg/pyramid/router.py",
>
> line 163, in handle_request
> response = view_callable(context, request)
> File
> "/home/taylor/projects/tacle/env34/lib/python3.4/site-packages/pyramid-1.5-py3.4.egg/pyramid/config/views.py",
>
> line 355, in rendered_view
> result = view(context, request)
> File
> "/home/taylor/projects/tacle/env34/lib/python3.4/site-packages/pyramid-1.5-py3.4.egg/pyramid/config/views.py",
>
> line 501, in _requestonly_view
> response = view(request)
> File "./tacle/event_views.py", line 63, in event_list
> caclient.connect(['127.0.0.1'])
> File "./cassaconn/clients.py", line 22, in connect
> self.session = cluster.connect()
> File
> "/home/taylor/projects/tacle/env34/lib/python3.4/site-packages/cassandra/cluster.py",
>
> line 546, in connect
> self.control_connection.connect()
> File
> "/home/taylor/projects/tacle/env34/lib/python3.4/site-packages/cassandra/cluster.py",
>
> line 1498, in connect
> self._set_new_connection(self._reconnect_internal())
> File
> "/home/taylor/projects/tacle/env34/lib/python3.4/site-packages/cassandra/cluster.py",
>
> line 1533, in _reconnect_internal
> raise NoHostAvailable("Unable to connect to any servers", errors)
> cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers',
> {'127.0.0.1': OperationTimedOut('errors=Timed out creating connection,
> last_host=None',)})
> [pid: 2130|app: 0|req: 2/2] 127.0.0.1 () {38 vars in 641 bytes} [Fri Jun
> 6 21:47:43 2014] GET /event_list => generated 0 bytes in 5007 msecs
> (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)
>
>
> And the view code:
>
> @view_config(route_name="event_list",
> renderer="templates/events/list_events.jinja2")
> def event_list(request):
> tacs = {}
> print('about to create client')
> caclient = SimpleClient()
> caclient.connect(['127.0.0.1'])
> print('able to connect to cassandra server')
> #caclient.catest()
> print("---------page reload-----------")
>
> return dict(resource=request.context, tacs=tacs)
>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.