龙卷风和 postgresql

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13661636/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:36:17  来源:igfitidea点击:

tornado and postgresql

pythonfacebookpostgresqltornado

提问by juk

I'm using demo from facebook's tornado

我正在使用来自facebook 的龙卷风的演示

But I don't want to use MySQL and trying to replace it with PG So I went ahead and modified like this :

但我不想使用 MySQL 并试图用 PG 替换它所以我继续修改如下:

define("port", default=8888, help="run on the given port", type=int)
define("pgsql_host", default="127.0.0.1:5432", help="blog database host")
define("pgsql_database", default="pgdb", help="blog database name")
define("pgsql_user", default="admin", help="blog database user")
define("pgsql_password", default="pgpass", help="blog database password")

and

        # Have one global connection to the blog DB across all handlers
    self.db = tornado.database.Connection(
        host=options.pgsql_host, database=options.pgsql_database,
        user=options.pgsql_user, password=options.pgsql_password)

But app just hangs when I run it, how to properly migrate it to PG?

但是当我运行它时应用程序就挂了,如何将其正确迁移到PG?

Actually I get error after some time:

实际上我在一段时间后收到错误:

    Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/tornado-2.4.1-py2.7.egg/tornado/database.py", line 84, in __init__
    self.reconnect()
  File "/usr/local/lib/python2.7/dist-packages/tornado-2.4.1-py2.7.egg/tornado/database.py", line 101, in reconnect
    self._db = MySQLdb.connect(**self._db_args)
  File "/usr/lib/pymodules/python2.7/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (2013, "Lost connection to MySQL server at 'reading initial communication packet', system error: 0")

Why is it connecting to MySQL?

为什么要连接到 MySQL?

回答by sufleR

Are you sure you can use it with different RDBMS including PostgreSQL? It uses torndbpackage which is written to work with MySQL.

您确定可以将它与包括 PostgreSQL 在内的不同 RDBMS 一起使用吗?它使用torndb包,该包是为与 MySQL 一起使用而编写的。

So i think that if you want to use it with PostgreSQL you should write your own torndb package for postgresql.

所以我认为如果你想将它与 PostgreSQL 一起使用,你应该为 postgresql 编写你自己的 torndb 包。

EDIT: As you can see at Tornado Wikiyou have to have postgresql wrapper (momokoor psycopg) there are some links for further study.

编辑:正如您在Tornado Wiki 上看到的,您必须拥有 postgresql 包装器(momokopsycopg),有一些链接可供进一步研究。

EDIT2: Momoko description:
"An asynchronous Psycopg2 wrapper for Tornado."

EDIT2:Momoko 描述:
“Tornado 的异步 Psycopg2 包装器。”

回答by Cole Maclean

tornado.database(which will be broken out of Tornado in 3.0) is a lightweight MySQL wrapper. It doesn't support anything other than MySQL.

tornado.database(它将在 3.0 中从 Tornado 中分离出来)是一个轻量级的 MySQL 包装器。它不支持 MySQL 以外的任何东西。

The good news is, as @sufleR noted, you have some options. You can use pyscopgdirectly, or you can use momoko, an async wrapper for pyscopg.

好消息是,正如@sufleR 所指出的,您有一些选择。您可以直接使用pyscopg,也可以使用momoko,它是 pyscopg 的异步包装器。