当前位置: 首页>>代码示例>>Python>>正文


Python Process.Daemon方法代码示例

本文整理汇总了Python中multiprocessing.Process.Daemon方法的典型用法代码示例。如果您正苦于以下问题:Python Process.Daemon方法的具体用法?Python Process.Daemon怎么用?Python Process.Daemon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在multiprocessing.Process的用法示例。


在下文中一共展示了Process.Daemon方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: assign_blocks

# 需要导入模块: from multiprocessing import Process [as 别名]
# 或者: from multiprocessing.Process import Daemon [as 别名]
def assign_blocks(centroids, data, processes):
'''
Inputs: list of centroids
        numpy array of blocks
        number of prcesses (integer)
Outputs: Calls graph function which plots every block

This function assigns each block to one of the centroids.
It's almost identical to using pool.map in linear_search_pool.py,
but since pool.map turned out to slow down the algorithm,
after consulting with Professor Wachs, we manually splitted up
the data into chunks and input each split chunk to each processor
which turned out to be approximately 'processes' times faster 
'''
    Districts = dc.create_districts(centroids)
    data = rm_centroids_from_data(centroids, data)

    q = Queue()

    colors_dict = get_colors(Districts)
   
    # used for stopping conditon with EPSILON
    unassigned_blocks = data.shape[0]

    while data.shape[0] != 0:
        data_splitted = split_data(data, processes)
        priority_district = dc.return_low_pop(Districts)

        for subdata in data_splitted:
            p = Process(target=find_nearest_block, args=(subdata, priority_district.centroid, q))
            p.Daemon = True
            p.start()

        for subdata in data_splitted:
            p.join()

        blocks = []
        while(not q.empty()):
            blocks.append(q.get())
        # [1:] part gets rid of the distance 
        nearest_block = list(min(blocks)[1:])

        plt.scatter(nearest_block[2], nearest_block[1], color=colors_dict[priority_district.id])

        priority_district.add_block(nearest_block, Districts) #should i get rid of distance before 
        idx = np.where(data[:,0] == nearest_block[0])
        data = np.delete(data, idx, 0)

        if (unassigned_blocks - EPSILON) == data.shape[0]:
           break

    graph(Districts, data)
开发者ID:jlu00,项目名称:cs123proj,代码行数:54,代码来源:linear_search_multiprocessing.py

示例2: searching_all

# 需要导入模块: from multiprocessing import Process [as 别名]
# 或者: from multiprocessing.Process import Daemon [as 别名]
def searching_all(filename, number):
	Grid, data, dim, lat, lon = build_grid(filename, number)
	
	Districts = dc.create_districts(CENTROID_L)
	unassigned_blocks = data.shape[0]

	q = Queue()
	processes = 5
	colors_dict = get_colors(Districts)
	
	while unassigned_blocks != 0:
		tol = 1
		priority_district = dc.return_low_pop(Districts)

		subset = searching_neighborhood(priority_district, tol, Grid, dim, lat, lon)
		print(subset.shape)

		split_subset = np.array_split(subset, processes)

		for subdata in split_subset:
			p = Process(target=find_nearest_block, args=(subdata, priority_district.centroid, q))
			p.Daemon = True
			p.start()

		for subdata in split_subset:
			p.join()

		while q.empty():
			tol += 1
			print("changed tolerance.")
			subset = searching_neighborhood(priority_district, tol, Grid, dim, lat, lon)

		blocks = []
		while(not q.empty()):
			blocks.append(q.get())
		nearest_block = list(min(blocks)[1:])

		priority_district.add_block(nearest_block[:-2], Districts)

		Grid[int(nearest_block[-2])][int(nearest_block[-1])].remove(nearest_block[:-2])
		plt.scatter(nearest_block[2], nearest_block[1], color=colors_dict[priority_district.id])
		unassigned_blocks -= 1

	graph(Districts, data)
开发者ID:jlu00,项目名称:cs123proj,代码行数:46,代码来源:grid_search_multiprocessing.py

示例3: JoinableQueue

# 需要导入模块: from multiprocessing import Process [as 别名]
# 或者: from multiprocessing.Process import Daemon [as 别名]
from time import sleep
#q是任务队列
#NUM是并发线程总数
#JOBS是有多少任务
q = JoinableQueue()
NUM = 12
JOBS = 100
#具体的处理函数,负责处理单个任务
def do_somthing_using(arguments):
    i=0
    while i < 100000:
        i += 1
    print(arguments)
#这个是工作进程,负责不断从队列取数据并处理
def working():
    while True:
        arguments = q.get()
        do_somthing_using(arguments)
#       sleep(1)
        q.task_done()
#fork NUM个线程等待队列
for i in range(NUM):
    t = Process(target=working)
    t.Daemon=True
    t.start()
#把JOBS排入队列
for i in range(JOBS):
    q.put(i)
#等待所有JOBS完成
q.join()
开发者ID:huiliu,项目名称:MPI,代码行数:32,代码来源:test_multiprocess.py

示例4: go

# 需要导入模块: from multiprocessing import Process [as 别名]
# 或者: from multiprocessing.Process import Daemon [as 别名]
 def go(scores, s, i):
     t = Process(target=worker, args=(scores, s, i))
     t.Daemon = True
     t.start()
开发者ID:jacobbrunson,项目名称:PSAT-Scores,代码行数:6,代码来源:scores.py


注:本文中的multiprocessing.Process.Daemon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。