Multi Threading Problem with Python + Django + PostgreSQL.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pradip

    Multi Threading Problem with Python + Django + PostgreSQL.

    Hello every body. I am new to this forum and also in Python.
    Read many things about multi threading in python. But still having
    problem.

    I am using Django Framework with Python having PostgreSQL as backend
    database with Linux OS. My applications are long running. I am using
    threading.
    The problem I am facing is that the connections that are being created
    for database(postgr es) update are not getting closed even though my
    threads had returned and updated database successfully. It is not like
    that the connections are not being reused. They r being reused but
    after sometime new one is created. Like this it creates too many
    connections and hence exceeding MAX_CONNECTION limit of postgres conf.

    ** I am using psycopg2 as adaptor for python to postgres connection.
    which itself handles the connections(ope n/close)

    Now the problem is with Django / Python / psycopg2 or any thing else??

    HELP ME OUT!!!!!
  • Nikita the Spider

    #2
    Re: Multi Threading Problem with Python + Django + PostgreSQL.

    In article
    <553b16a7-a89e-4892-b92b-c0f88e00e096@e2 3g2000prf.googl egroups.com>,
    Pradip <pradipbhosale@ gmail.comwrote:
    Hello every body. I am new to this forum and also in Python.
    Read many things about multi threading in python. But still having
    problem.
    >
    I am using Django Framework with Python having PostgreSQL as backend
    database with Linux OS. My applications are long running. I am using
    threading.
    The problem I am facing is that the connections that are being created
    for database(postgr es) update are not getting closed even though my
    threads had returned and updated database successfully. It is not like
    that the connections are not being reused. They r being reused but
    after sometime new one is created. Like this it creates too many
    connections and hence exceeding MAX_CONNECTION limit of postgres conf.
    >
    ** I am using psycopg2 as adaptor for python to postgres connection.
    which itself handles the connections(ope n/close)
    Hi Pradip,
    A common problem that new users of Python encounter is that they expect
    database statements to COMMIT automatically. Psycopg2 follows the Python
    DB-API specification and does not autocommit transactions unless you ask
    it to do so. Perhaps your connections are not closing because they have
    open transactions?

    To enable autocommit, call this on your connection object:
    connection.set_ isolation_level (psycopg2.exten sions.ISOLATION _LEVEL_AUTOCO
    MMIT)
    Now the problem is with Django / Python / psycopg2 or any thing else??
    Are you asking if there are bugs in this code that are responsible for
    your persistent connections? If so, then I'd say the answer is almost
    certainly no. Of course it's possible, but Django/Psycopg/Postgres is a
    pretty popular stack. The odds that there's a major bug in this popular
    code examined by many eyes versus a bug in your code are pretty low, I
    think. Don't take it personally, the same applies to my me and my code.
    =)

    Happy debugging

    --
    Philip

    Whole-site HTML validation, link checking and more

    Comment

    Working...