多处理在 psycopg2 2.8.3 版本中失败



我已经将psycopg2版本更新到2.8.3。执行该多处理连接池后失败。 错误回溯

"""
Traceback (most recent call last):
File "/usr/local/lib/python3.5/multiprocessing/pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "/usr/local/lib/python3.5/multiprocessing/pool.py", line 44, in mapstar
return list(map(*args))
File "/app/project/utils/ddr_algorithm_main.py", line 461, in get_actual_datapoints
years_in_practice = ddr_obj.get_years_in_practice(single_data_list_static)
File "/app/project/utils/ddr_report_algorithm.py", line 436, in get_years_in_practice
provider_data[3])
File "/app/project/utils/ddr_report_algorithm.py", line 477, in get_single_provider_years_in_practice_list
list_result = [int(str(i[0]).split(',')[1]) for i in provider_years_in_practice_list if
File "/app/project/utils/ddr_report_algorithm.py", line 478, in <listcomp>
i[0] and str(i[0]).split(',').__len__() > 1]
ValueError: invalid literal for int() with base 10: ' 1994)'
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 29, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/app/project/medical_info/management/commands/ddr_data_points.py", line 13, in handle
ddr_main_class_obj.main()
File "/app/project/utils/ddr_algorithm_main.py", line 358, in main
create_datapoints = calculateParallel(provider_ids, threads=30)
File "/app/project/utils/ddr_algorithm_main.py", line 554, in calculateParallel
results = pool.map(class_obj.get_actual_datapoints, provider_ids)
File "/usr/local/lib/python3.5/multiprocessing/pool.py", line 266, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "/usr/local/lib/python3.5/multiprocessing/pool.py", line 644, in get
raise self._value
ValueError: invalid literal for int() with base 10: ' 1994)'

这是在我更新到 psycopg2 版本 2.8.3 之后发生的

代码狙击

def calculateParallel(provider_ids, threads=None):
for name, info in django.db.connections.databases.items():  # Close the DB connections
django.db.connection.close()
pool = ThreadPool(threads)
class_obj = MainDataClass()
results = pool.map(class_obj.get_actual_datapoints, provider_ids)
pool.close()
pool.join()
return results

我更新 psycopg2版本的原因是多线程在版本中失败 psycopg2==2.7.4。

使用 psycopg2-binary 应用程序可以工作,但我的一个 Django 自定义管理命令失败了。

管理命令在版本 2.7.4 上完美运行,但多线程失败。

在版本 2.8.3 上,多线程工作,但管理命令失败。

我不确定我需要改变什么。而且我很确定上述错误回溯是由于psycopg2版本的更改。对于旧版本,它可以正常工作。

我收到错误的代码。

provider_years_in_practice_list = self.query(sql_single_provider_years_in_practice_list)
if provider_years_in_practice_list:
list_result = [int(str(i[0]).split(',')[1]) for i in provider_years_in_practice_list if
i[0] and str(i[0]).split(',').__len__() > 1]
list_result = list(set(list_result))  # remove the year duplications

列表"provider_years_in_practice_list"包含数字范围类型元素。

修复是

if provider_years_in_practice_list:
list_result = [int(i[0].upper) for i in provider_years_in_practice_list if
i[0] and i[0].upper]

相关内容

  • 没有找到相关文章

最新更新