Closed yoosofan closed 8 years ago
How about
future = conn.connect()
ioloop.add_future(future, lambda x: ioloop.stop())
ioloop.start()
...
On 31 May 2016 12:18, "Ahmad Yoosofan" notifications@github.com wrote:
My project needs time consuming queries. Therefore, Momoko seems the best answer.But I couldn't even run the first sample of Momoko. What is the problem of the following code:
import psycopg2 import momoko from tornado.ioloop import IOLoop ioloop = IOLoop.instance()
dsn= 'dbname=db1 user=postgres password=myPass host=127.0.0.1 port=5432' conn = momoko.Connection(dsn=dsn) future = ioloop.add_future(conn.connect(), lambda x: ioloop.stop()) ioloop.start() print(type(future)) future.result() # raises exception on connection error
future = conn.execute("SELECT 1") ioloop.add_future(future, lambda x: ioloop.stop()) ioloop.start() cursor = future.result() rows = cursor.fetchall() for m1 in rows: print(m1)
Error : Python3 on Ubuntu 16.04 with latest packages
Traceback (most recent call last): File "test.01.py", line 11, in future.result() # raises exception on connection error AttributeError: 'NoneType' object has no attribute 'result'
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/FSX/momoko/issues/143, or mute the thread https://github.com/notifications/unsubscribe/AADjWdbbg0bP3uQ34MjF84FBrXG-WRh0ks5qG_zWgaJpZM4IqVOC .
Btw,
You don't really need a future for connect
operation.
On 31 May 2016 12:31, "Zaar Hai" haizaar@gmail.com wrote:
How about
future = conn.connect() ioloop.add_future(future, lambda x: ioloop.stop()) ioloop.start() ...
On 31 May 2016 12:18, "Ahmad Yoosofan" notifications@github.com wrote:
My project needs time consuming queries. Therefore, Momoko seems the best answer.But I couldn't even run the first sample of Momoko. What is the problem of the following code:
import psycopg2 import momoko from tornado.ioloop import IOLoop ioloop = IOLoop.instance()
dsn= 'dbname=db1 user=postgres password=myPass host=127.0.0.1 port=5432' conn = momoko.Connection(dsn=dsn) future = ioloop.add_future(conn.connect(), lambda x: ioloop.stop()) ioloop.start() print(type(future)) future.result() # raises exception on connection error
future = conn.execute("SELECT 1") ioloop.add_future(future, lambda x: ioloop.stop()) ioloop.start() cursor = future.result() rows = cursor.fetchall() for m1 in rows: print(m1)
Error : Python3 on Ubuntu 16.04 with latest packages
Traceback (most recent call last): File "test.01.py", line 11, in future.result() # raises exception on connection error AttributeError: 'NoneType' object has no attribute 'result'
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/FSX/momoko/issues/143, or mute the thread https://github.com/notifications/unsubscribe/AADjWdbbg0bP3uQ34MjF84FBrXG-WRh0ks5qG_zWgaJpZM4IqVOC .
Thank you, my problem solved. The corrected code is:
import psycopg2
import momoko
from tornado.ioloop import IOLoop
ioloop = IOLoop.instance()
dsn = "dbname=db user=postgres password=myPass host=127.0.0.1 port=5432"
conn = momoko.Pool(dsn=dsn)
future = conn.connect()
ioloop.add_future(future, lambda x: ioloop.stop())
ioloop.start()
future.result() # raises exception on connection error
future = conn.execute("SELECT 1")
ioloop.add_future(future, lambda x: ioloop.stop())
ioloop.start()
cursor = future.result()
rows = cursor.fetchall()
for m1 in rows:
print(m1)
Here is simpler code:
import psycopg2
import momoko
from tornado.ioloop import IOLoop
ioloop = IOLoop.instance()
dsn = "dbname=db user=postgres password=myPass host=127.0.0.1 port=5432"
conn = momoko.Pool(dsn=dsn)
ioloop.add_future(conn.connect(), lambda x: ioloop.stop())
ioloop.start()
future = conn.execute("SELECT 1")
ioloop.add_future(future, lambda x: ioloop.stop())
ioloop.start()
cursor = future.result()
rows = cursor.fetchall()
for m1 in rows: print(m1)
My bad - you do need to check future
's result for connect operation if you want to catch connection errors.
My project needs time consuming queries. Therefore, Momoko seems the best answer.But I couldn't even run the first sample of Momoko. What is the problem of the following code:
Error : Python3 on Ubuntu 16.04 with latest packages <class 'NoneType'> Traceback (most recent call last): File "test.01.py", line 11, in
future.result() # raises exception on connection error
AttributeError: 'NoneType' object has no attribute 'result'