Code Monkey home page Code Monkey logo

Comments (6)

haizaar avatar haizaar commented on July 22, 2024

How about

future = conn.connect()
ioloop.add_future(future, lambda x: ioloop.stop())
ioloop.start()
...

On 31 May 2016 12:18, "Ahmad Yoosofan" [email protected] 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
#143, or mute the thread
https://github.com/notifications/unsubscribe/AADjWdbbg0bP3uQ34MjF84FBrXG-WRh0ks5qG_zWgaJpZM4IqVOC
.

from momoko.

haizaar avatar haizaar commented on July 22, 2024

Btw,
You don't really need a future for connect operation.
On 31 May 2016 12:31, "Zaar Hai" [email protected] wrote:

How about

future = conn.connect()
ioloop.add_future(future, lambda x: ioloop.stop())
ioloop.start()
...

On 31 May 2016 12:18, "Ahmad Yoosofan" [email protected] 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
#143, or mute the thread
https://github.com/notifications/unsubscribe/AADjWdbbg0bP3uQ34MjF84FBrXG-WRh0ks5qG_zWgaJpZM4IqVOC
.

from momoko.

yoosofan avatar yoosofan commented on July 22, 2024

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)

from momoko.

yoosofan avatar yoosofan commented on July 22, 2024

Please change the sample of the first page on tutorial

from momoko.

yoosofan avatar yoosofan commented on July 22, 2024

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)

from momoko.

haizaar avatar haizaar commented on July 22, 2024

My bad - you do need to check future's result for connect operation if you want to catch connection errors.

from momoko.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.