当前位置:网站首页>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
边栏推荐
- Vulnhub靶机--DC8
- Threatless Technology-TVD Daily Vulnerability Intelligence-2022-7-31
- SSL证书为什么要选付费?
- visio文件批量转pdf
- Threatless Technology-TVD Daily Vulnerability Intelligence-2022-8-1
- 网络安全学习小结--kali基本工具、webshell、代码审计
- CLUSTER DAY03 (Ceph overview, the deployment of Ceph CLUSTER, Ceph block storage)
- mongo-express 远程代码执行漏洞复现
- uboot sets the default bootdelay
- MySQL中忘记用户密码怎么办?
猜你喜欢
CLUSTER DAY03 (Ceph overview, the deployment of Ceph CLUSTER, Ceph block storage)
Drupal 远程代码执行漏洞复现(CVE-2018-7602)
ETCD cluster fault emergency recovery - to recover from the snapshot
mongo-express 远程代码执行漏洞复现
SECURITY DAY04( Prometheus服务器 、 Prometheus被监控端 、 Grafana 、 监控数据库)
Project Notes - Random 2
照片的35x45,300dpi怎么弄
CLUSTER DAY01 (Introduction to cluster and LVS, LVS-NAT cluster, LVS-DR cluster)
VMware workstation 16 installation and configuration
GoAhead Server 环境变量注入(CVE-2021-42342)漏洞复现
随机推荐
(三)软件测试理论(了解软件的缺陷知识)
Threatless Technology-TVD Daily Vulnerability Intelligence-2022-7-29
无胁科技-TVD每日漏洞情报-2022-7-29
2022年全国职业技能大赛网络安全竞赛试题B模块自己解析思路(1)
AUTOMATION DAY07( Ansible Vault 、 普通用户使用ansible)
查看CPU和其他硬件温度的软件
SECURITY DAY02 (Zabbix alarm mechanism, Zabbix advanced operation and monitoring case)
VMware workstation 16 installation and configuration
HPC平台搭建
ansible batch install zabbix-agent
[HTB]渗透Backdoor靶机
勒索病毒eking.devos.mkp.makop.lockbit.eight.locked.roger等剖析及中毒文件恢复
uboot sets the default bootdelay
文本三剑客——awk 截取+过滤+统计
无胁科技-TVD每日漏洞情报-2022-7-27
CLUSTER DAY01 (Introduction to cluster and LVS, LVS-NAT cluster, LVS-DR cluster)
uboot设置默认的bootdelay
CLUSTER DAY04(块存储应用案例 、 分布式文件系统 、 对象存储)
(1) Software testing theory (0 basic understanding of basic knowledge)
项目笔记——随机2