【问题标题】:Parallel table update using python multiprocessing (PostGIS/PostgreSQL)使用 python 多处理 (PostGIS/PostgreSQL) 的并行表更新
【发布时间】:2015-06-08 11:21:51
【问题描述】:

您好,我一直在使用多处理方法从 here 更新一个巨大的 postgis 表,它工作得很好,但是我的表似乎没有得到更新,除非我在 commit; 语句/p>

procQuery = 'UPDATE city SET gid_fkey = gid FROM country  WHERE ST_within((SELECT the_geom FROM city WHERE city_id = %s), country.the_geom) AND city_id = %s' % (self.a, self.a)

喜欢

procQuery = 'UPDATE city SET gid_fkey = gid FROM country  WHERE ST_within((SELECT the_geom FROM city WHERE city_id = %s), country.the_geom) AND city_id = %s;commit;' % (self.a, self.a)

这可能是什么问题?

【问题讨论】:

  • 这对你来说有什么意义? commit updateinsertdelete 查询是 SQL 的事情。也许您认为您的数据库事务对象已将自动提交设置为 true。可能值得先检查一下。

标签: python postgresql parallel-processing multiprocessing psycopg2


【解决方案1】:

好的,我通过将连接设置为 autommit = True 解决了

class Consumer(multiprocessing.Process):

def __init__(self, task_queue, result_queue):

    multiprocessing.Process.__init__(self)
    self.task_queue = task_queue
    self.result_queue = result_queue
    self.pyConn = psycopg2.connect(**connstring)
    self.pyConn.autocommit = True


def run(self):
    proc_name = self.name
    while True:
        next_task = self.task_queue.get()
        if next_task is None:
            print 'Tasks Complete'
            self.task_queue.task_done()
            break            
        answer = next_task(connection=self.pyConn)
        self.task_queue.task_done()
        self.result_queue.put(answer)
    return

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多