python不等待返回_Python:启动psql查询,不要等待响应

我正在使用python和psycopg2启动COPY TO CSV,这将需要很长时间(可能数小时).复制到文件的工作将由postgres处理,因此无需将任何信息返回给我的python脚本.

有没有一种方法可以将查询传递给postgres,然后不等待响应就断开连接,以便我的程序可以执行其他任务?

这是开始工作的方法:

def startJob(self):

#This bit will take the information and flags from the file and start the psql job

conn = psycopg2.connect('dbname=mydb user=postgres')

cur = conn.cursor()

beginClause = "COPY ("

selectClause = """SELECT '%s' FROM db """ % ','.join(self.flags)

whenClause = """WHERE 'start' BETWEEN '%s' AND '%s'""" % self.info['begin'] self.info['end']

destClause = """) TO '/dest/%s' WITH CSV HEADER""" % self.name

fullQuery = beginClause + selectClause + whenClause + destClause

#I want the execute to start the job, and then return so that I can

#resume regular operation of the program

cur.execute(fullQuery)

conn.close()

self.changeStatus('progress')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值