Created
October 20, 2017 10:05
-
-
Save AlexArcPy/2483a0da8c0885d90d3525a0e403a80f to your computer and use it in GitHub Desktop.
Some snippets for Python concurrent multiprocessing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
import time | |
from datetime import datetime | |
import arcpy | |
from concurrent import futures | |
HOME = r"C:\GIS\Temp\cc" | |
#RANGES = [x for x in range(10000, 80000, 10000)] #63 secs | |
#RANGES = [x for x in range(10000, 200000, 20000)] #168 secs | |
#---------------------------------------------------------------------- | |
def create_one_fc(num): | |
"""""" | |
print(num) | |
path = os.path.join(HOME, datetime.now().strftime('%Y%m%d_%H%M%S%f')) | |
os.mkdir(path) | |
arcpy.CreateRandomPoints_management( | |
out_path=os.path.join(path), | |
out_name="sample{}".format('randompnts.shp'), | |
constraining_feature_class=r"C:\GIS\Temp\Gpd\Roads.shp", | |
number_of_points_or_field=num) | |
return num | |
#---------------------------------------------------------------------- | |
def create_many_fcs(RANGES): | |
"""""" | |
with futures.ProcessPoolExecutor() as executor: | |
res = executor.map(create_one_fc, RANGES) | |
return len(list(res)) | |
#---------------------------------------------------------------------- | |
def main(create_many_fcs): | |
"""""" | |
create_many_fcs(RANGES) | |
if __name__ == '__main__': | |
#create_many_fcs([x for x in range(10000, 80000, 10000)]) | |
results = [] | |
for i in range(20, 40, 2): #* 10 = 32secs, *20 =43secs | |
print('----', i, '----') | |
t0 = time.time() | |
RANGES = [10000] * i | |
main(create_many_fcs) | |
runtime = time.time() - t0 | |
print(runtime) | |
results.append((i, runtime)) | |
print(results) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
import arcpy | |
from concurrent import futures | |
HOME = r"C:\GIS\Temp\cc" | |
#RANGES = [x for x in range(10000, 80000, 10000)] #127 secs | |
RANGES = [x for x in range(10000, 200000, 20000)] #438 secs | |
t0 = time.time() | |
for num in RANGES: | |
print(num) | |
arcpy.CreateRandomPoints_management(out_path=os.path.join(HOME, 'out.gdb'), | |
out_name="sample{}".format(num), | |
constraining_feature_class=r"C:\GIS\Temp\Gpd\Roads.shp", | |
number_of_points_or_field=num) | |
print(time.time() - t0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment