FSX / momoko

Wraps (asynchronous) Psycopg2 for Tornado.
http://momoko.61924.nl/
Other
363 stars 73 forks source link

OSError: [Errno 2] No such file or directory #84

Closed danielknell closed 9 years ago

danielknell commented 9 years ago

I was evaluating momoko for a project and noticed it was throwing errors if i instantiate the connection pool, trying to track this down i took the example from the momoko manual and that is also throwing the error,

this is running on OSX with the home brew version of python 2.7.3

$ cat test.py
from tornado import gen
from tornado.ioloop import IOLoop
from tornado.httpserver import HTTPServer
from tornado.options import parse_command_line
from tornado.web import *

import psycopg2
import momoko

class BaseHandler(RequestHandler):
    @property
    def db(self):
        return self.application.db

class TutorialHandler(BaseHandler):
    def get(self):
        self.write('Some text here!')
        self.finish()

if __name__ == '__main__':
    parse_command_line()
    application = Application([
        (r'/', TutorialHandler)
    ], debug=True)

    application.db = momoko.Pool(
        dsn='dbname=your_db user=your_user password=very_secret_password '
            'host=localhost port=5432',
        size=1
    )

    http_server = HTTPServer(application)
    http_server.listen(8888, 'localhost')
    IOLoop.instance().start()

$ python -m test
[I 141119 14:42:04 connection:536] Opening new database connection
[E 141119 14:42:04 ioloop:585] Exception in callback (8, <function null_wrapper at 0x104b337d0>)
    Traceback (most recent call last):
      File "/Users/daniel/.venvs/foo/lib/python2.7/site-packages/tornado/ioloop.py", line 837, in start
        handler_func(fd_obj, events)
      File "/Users/daniel/.venvs/foo/lib/python2.7/site-packages/tornado/stack_context.py", line 275, in null_wrapper
        return fn(*args, **kwargs)
      File "/Users/daniel/.venvs/foo/lib/python2.7/site-packages/momoko/connection.py", line 599, in io_callback
        self.ioloop.update_handler(self.fileno, IOLoop.WRITE)
      File "/Users/daniel/.venvs/foo/lib/python2.7/site-packages/tornado/ioloop.py", line 681, in update_handler
        self._impl.modify(fd, events | self.ERROR)
      File "/Users/daniel/.venvs/foo/lib/python2.7/site-packages/tornado/platform/kqueue.py", line 45, in modify
        self.unregister(fd)
      File "/Users/daniel/.venvs/foo/lib/python2.7/site-packages/tornado/platform/kqueue.py", line 50, in unregister
        self._control(fd, events, select.KQ_EV_DELETE)
      File "/Users/daniel/.venvs/foo/lib/python2.7/site-packages/tornado/platform/kqueue.py", line 64, in _control
        self._kqueue.control([kevent], 0)
    OSError: [Errno 2] No such file or directory
^CTraceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/Users/daniel/foo/test.py", line 37, in <module>
    IOLoop.instance().start()
  File "/Users/daniel/.venvs/foo/lib/python2.7/site-packages/tornado/ioloop.py", line 812, in start
    event_pairs = self._impl.poll(poll_timeout)
  File "/Users/daniel/.venvs/foo/lib/python2.7/site-packages/tornado/platform/kqueue.py", line 67, in poll
    kevents = self._kqueue.control(None, 1000, timeout)
KeyboardInterrupt

$ python --version
Python 2.7.3

$ pip freeze
Momoko==1.1.5
backports.ssl-match-hostname==3.4.0.2
brukva==0.0.1
certifi==14.05.14
geoip2==2.0.2
psycopg2==2.5.4
requests==2.4.3
tornado==4.0.2
wsgiref==0.1.2
haizaar commented 9 years ago

I've tried your code with correct username, db and password and it works OK. Then I've changed it to invalid credentials and got the your error you've got.

I would double-check that your dsn is correct (with stand-alone psycopg2). psycopg2 async behavior when connecting to db server through Unix socket is rather subtle, that's why the error is so confusing.

Also bear in mind that if you want support for automatic reconnected you need to pass raise_connect_errors=False to Pool constructor.

danielknell commented 9 years ago

thanks, it seems the error was localhost vs 127.0.0.1 as i did not want to use the unix socket, although psycopg2 seems to do the right then when connecting synchronously, so the fact it was defaulting to unix sockets threw me.

all working, just a pretty confusing error message.

haizaar commented 9 years ago

Yeah, they all do that, mysql as well.

I'm glad you've solved your issue and thanks for the feedback.