本文整理汇总了Python中helper.Helper.start方法的典型用法代码示例。如果您正苦于以下问题:Python Helper.start方法的具体用法?Python Helper.start怎么用?Python Helper.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helper.Helper
的用法示例。
在下文中一共展示了Helper.start方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compute_matrix_block
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import start [as 别名]
def compute_matrix_block(self, start_row, start_column, num_rows, num_columns):
"""
Computes a given block of the result matrix.
The method invoked by FEP nodes.
@param start_row: the index of the first row in the block
@param start_column: the index of the first column in the block
@param num_rows: number of rows in the block
@param num_columns: number of columns in the block
@return: the block of the result matrix encoded as a row-order list of lists of integers
"""
"""
This method is searching for the elements that this node needs in order to compute his block.
Firstly finds the node from where a element should be taken, starts a thread which will obtain the element, and then
puts that element in a matrix.
Those are made twice, for each matrix.
After calculating the two matrixes, the method 'multiply' gives the result that is returning the result.
"""
A = [[0 for i in range(self.matrix_size)] for j in range(num_rows)];
B = [[0 for j in range(num_columns)] for j in range(self.matrix_size)];
for i in range(num_rows):
for j in range(self.matrix_size):
row = start_row + i;
id_row = row / self.block_size;
id_column = j / self.block_size;
node = self.nodes[(self.matrix_size / self.block_size) * id_row + id_column];
i_a = node.node_ID[0];
j_a = node.node_ID[1];
size = node.block_size;
helper = Helper(node, row - i_a * size, j - j_a * size, "a");
helper.start();
helper.join();
A[i][j] = helper.element;
for i in range(self.matrix_size):
for j in range(num_columns):
column = start_column + j;
id_row = i / self.block_size;
id_column = column / self.block_size;
node = self.nodes[(self.matrix_size / self.block_size) * id_row + id_column];
i_b = node.node_ID[0];
j_b = node.node_ID[1];
size = node.block_size;
helper = Helper(node, i - i_b * size, column - j_b * size, "b");
helper.start();
helper.join();
B[i][j] = helper.element;
return self.multiply(A, B, num_rows, num_columns);
示例2: Server
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import start [as 别名]
class Server(object):
def __init__(self, name, port=None, use_bonjour=False, data_callback=None, validate_result=None):
'''note that data_callback must be thread safe'''
self.port = port or 8139
self.jobnum = 0
self.queue = deque()
self.completed = {}
self.lock = threading.Lock()
self.use_bonjour = use_bonjour
self.data_callback = data_callback
self.validate_result = validate_result
self.serving = False
self.helper = Helper(self, self.port)
def add_work(self, work_blob):
with self.lock:
self.queue.append((self.jobnum, work_blob))
this_job = self.jobnum
self.jobnum += 1
return this_job
def fetch_result(self, jobnum=None):
with self.lock:
if jobnum is None:
if len(self.completed):
jobnum = self.completed.keys()[0]
else:
return None
if jobnum in self.completed:
return self.completed.pop(jobnum)
return None
def next_job(self):
with self.lock:
if len(self.queue) > 0:
jobnum, work_blob = self.queue[0]
self.queue.rotate(-1)
return "%d %s"%(jobnum, work_blob)
else:
return "NOWORK"
def receive_work(self, jobnum, result_dict):
# XXX - this should probably cache results in files, to prevent overload
# XXX - need to check work is valid before removing from work queue
if self.validate_result is not None:
if not self.validate_result(result_dict):
sys.stderr.write("NUAGEUX: job %s not accepted\n"%(jobnum))
return
with self.lock:
# only accept the first answer, though we could do some consistency checks here.
if jobnum not in self.completed:
self.completed[jobnum] = result_dict
# This seems the easiest way to remove from the queue given only the jobnum
# (I guess we could add a self.jobnum_to_work dict, but would it be cleaner?)
for idx in range(len(self.queue)):
if self.queue[0][0] == jobnum:
self.queue.popleft()
self.queue.rotate(1)
def start(self):
self.helper.start(self.port)
def stop(self):
self.helper.stop()
def clear(self):
with self.lock:
self.queue.clear()
self.completed = {}
def base_URL(self):
return 'http://%s:%d'%(socket.getfqdn(), self.port)
def advertise(self, name, protocol):
assert protocol[0].isalpha() and (len(protocol) < 16) and protocol.replace('-', '').isalpha(), "protocol must be alphanumeric+dashes, <= 15 characters, and start with alphanumeric"
self.helper.advertise(name, protocol)