我有一个oracle查询,它返回了我约300万行,看起来像这样:
select key from table;---just one column
我试图使用python中的pom对象在python
中的模块并行执行此操作。import threading
local = threading.local()
def execute_query:
if not hasattr(local, 'db'):
local.db = params.get('conn')
cursor = local.db.cursor()
cursor.execute(params.get('sql'))
return cursor.fetchall()
和,要在并行执行上述上述Oracle查询:
def __call__(self):
pool = Pool(10)
data = pool.apply(execute_query, [{ 'conn' : self._connection, 'sql': self._sql }])
pool.close()
pool.join()
我知道pool object
的apply method
仅在一个工作线程中执行传递的函数。
有什么办法可以在多个线程之间执行此execute_query
以提高性能?
问题:我正在尝试并行执行此操作。
apply(func[, args[, kwds]])
Call func with arguments args and keyword arguments kwds.
It blocks until the result is ready.
Given this blocks, apply_async() is better suited for performing work in parallel.
Additionally, func is only executed in one of the workers of the pool.