postgresql - Python: Start psql query, don't wait for response -
i using python , psycopg2 start re-create csv take long time (possibly hours). re-create file work handled postgres, no info needs returned python script.
is there way me pass query postgres, , disconnect without waiting response programme can work on other tasks?
here method starts job:
def startjob(self): #this bit take info , flags file , start psql job conn = psycopg2.connect('dbname=mydb user=postgres') cur = conn.cursor() beginclause = "copy (" selectclause = """select '%s' db """ % ','.join(self.flags) whenclause = """where 'start' between '%s' , '%s'""" % self.info['begin'] self.info['end'] destclause = """) '/dest/%s' csv header""" % self.name fullquery = beginclause + selectclause + whenclause + destclause #i want execute start job, , homecoming can #resume regular operation of programme cur.execute(fullquery) conn.close() self.changestatus('progress')
there async ability in psycopg2, can't disconnect, can run job in background , wait result (if wish). see:
http://initd.org/psycopg/docs/advanced.html
about halfway down:
conn = psycopg2.connect(database='mydb', async=1)
if run job on connection should able allow run without program's attendance. if want jump in async both feet, recommend looking @ txpostgres.
http://txpostgres.readthedocs.org/
-g
python postgresql psycopg2
No comments:
Post a Comment