python - 金字塔和卡桑德拉不能正常工作

python - 金字塔和卡桑德拉不能正常工作,第1张

我使用金字塔(1.5.7)女服务员(0.8.9) Cassandra(2.2.0)。似乎Waitress和Cassandra司机正在使用asyncore,不知怎的,他们正在踩着对方的脚趾。这是我在 app / __ init __。py 文件中的代码:

import logging.config
from .action.context import root_factory
from pyramid.config import Configurator
from cassandra.cluster import Cluster
from cassandra.query import named_tuple_factory


def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application."""

    # support logging in python3
    logging.config.fileConfig(
        settings['logging.config'],
        disable_existing_loggers=False
    )
    config = Configurator(settings=settings, root_factory=root_factory)
    # Retrieves connection to Cassandra (Non SQL database)
    def get_non_sql(request):
        cluster = Cluster(['127.0.0.1'], port=9042)
        session = cluster.connect('app')
        def disconnect(request):
            cluster.shutdown()
        request.add_finished_callback(disconnect)
        return cluster.connect('app')

    #Adding scheduler configuration
    config.configure_celery(global_config['__file__'])
    config.add_request_method(get_non_sql, 'non_sql', reify=True)
    config.scan()
    return config.make_wsgi_app()

生成的错误:

2015-07-27 12:24:36,779 ERROR [waitress][cassandra_driver_event_loop] Socket error.
Traceback (most recent call last):
  File "python3.4/site-packages/waitress-0.8.9-py3.4.egg/waitress/channel.py", line 167, in handle_read
    data = self.recv(self.adj.recv_bytes)
  File "python3.4/asyncore.py", line 379, in recv
    data = self.socket.recv(buffer_size)
BlockingIOError: [Errno 35] Resource temporarily unavailable
2015-07-27 12:24:37,079 ERROR [waitress][MainThread] Unexpected exception when flushing.
  File "python3.4/site-packages/waitress-0.8.9-py3.4.egg/waitress/server.py", line 154, in run
    use_poll=self.adj.asyncore_use_poll,
  File "python3.4/asyncore.py", line 208, in loop
    poll_fun(timeout, map)
  File "python3.4/asyncore.py", line 145, in poll
    r, w, e = select.select(r, w, e, timeout)
OSError: [Errno 9] Bad file descriptor
2015-07-27 12:33:32,649 DEBUG [cassandra.io.asyncorereactor][cassandra_driver_event_loop] Asyncore event loop ended

是否有人知道此问题的解决方法?

最佳答案:

1 个答案:

答案 0 :(得分:3)

女服务员 cassandra-driver 正在使用相同的套接字。我删除了女服务员的 0.8.9 版本并安装了最新的开发版本(分支)

pip uninstall waitress
pip install git git://github.com/Pylons/waitress@master

此版本中的asyncore套接字已更改,因此可以完美运行。 尽管如此,我建议使用libev代替它,它似乎比asyncore有更好的性能。在OS X中,它就像安装 libev 库一样简单:

brew install libev

执行此操作后,立即安装 cassandra-driver (它会自动检测 libev 库)

pip install cassandra-driver

然后只使用 LibevConnection 类:

from cassandra.io.libevreactor import LibevConnection 
from cassandra.cluster import Cluster 


cluster = Cluster() 
cluster.connection_class = LibevConnection 
session = cluster.connect()
本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复