当前位置:网站首页>arcmap下的多进程脚本
arcmap下的多进程脚本
2022-08-11 05:33:00 【我是无名的我】
arcmap中多为CPU密集运算,最好的方式为使用多进程而不是多线程(IO密集)
问题:python多进程无法正常在arcmap下正常开启
原因:arcmap下信息处理时,调用的时内置的py内核,但是一个arcmap进程只能调用一个py内核。
解决:使用外置的py内核,为保证兼容性,用2.7X 32位,必须把工作代码跟main
函数分开。
实例代码:
代码简单实现了数据的输入,并调用了arcpy。
# -*- coding: utf-8 -*-
""" Created on Thu Mar 12 19:12:59 2020 @author: zonggongban HGH """
import arcpy
import os
import sys
def worker_function(x):
name = os.path.join('E:/p', str(x) + '.txt')
with open(name, 'w') as f:
f.write(sys.version)
arcpy.AddMessage(999)
print(arcpy.GetMessages())
return name
将上述脚本命名为worker.py
# -*- coding: utf-8 -*-
""" Created on Thu Mar 12 19:12:59 2020 @author: zonggongban HGH """
import os
import arcpy
import multiprocessing
import time
import worker
def main():
''' 调用外置py内核 '''
multiprocessing.set_executable('G:/anaconda27/pythonw.exe')
pool = multiprocessing.Pool()
time.sleep(0.0001)
for i in [1, 2]:
pool.apply_async(work.worker_function, (i,)) # args are passed as a list
pool.close()
pool.join()
if __name__=='__main__':
asters = arcpy.GetParameterAsText(0)
main()
在主函数调用work.py
参考
can-multiprocessing-with-arcpy-be-run-in-a-script-tool
Create a script tool that uses multiprocessing
边栏推荐
- uboot设置默认的bootdelay
- 无胁科技-TVD每日漏洞情报-2022-7-29
- Django QuerySet.order_by() SQL注入漏洞复现
- Threatless Technology-TVD Daily Vulnerability Intelligence-2022-7-29
- Es common operations and classical case
- Two hundred questions in C language (0 basic continuous update) (1~5)
- (一)软件测试理论(0基础了解基础知识)
- GoAhead Server 环境变量注入(CVE-2021-42342)漏洞复现
- Threatless Technology-TVD Daily Vulnerability Intelligence-2022-7-25
- Vulnhub靶机--born2root
猜你喜欢
随机推荐
CLUSTER DAY04 (Block Storage Use Cases, Distributed File Systems, Object Storage)
MoreFileRename batch file renaming tool
C语言两百题(0基础持续更新)(1~5)
本地yum源搭建
ETCD集群故障应急恢复-从snapshot恢复
Threatless Technology-TVD Daily Vulnerability Intelligence-2022-7-28
ETCD集群故障应急恢复-本地数据可用
SECURITY DAY06 ( iptables firewall, filter table control, extended matching, typical application of nat table)
Threatless Technology-TVD Daily Vulnerability Intelligence-2022-8-1
Es常用操作和经典case整理
FusionCompute8.0.0实验(1)CNA及VRM安装
vulnhub靶机--6Day_Lab-v1.0.1
No threat of science and technology - TVD vulnerability information daily - 2022-7-21
无胁科技-TVD每日漏洞情报-2022-8-7
(一)软件测试理论(0基础了解基础知识)
AUTOMATION DAY07 (Ansible Vault, ordinary users use ansible)
实操指南:多个域名该买哪种SSL证书?
mongo-express 远程代码执行漏洞复现
项目笔记——随机2
CLUSTER DAY01 (Introduction to cluster and LVS, LVS-NAT cluster, LVS-DR cluster)