Beispiel #1
0
# MULTIPROCESSING

from multiprocessing import Process
import os

def squared_number():
    for i in range(1000):
        i * i
if __name__ == "__main__":
    processes = []
    num_process = os.cpu_count()
for i in range (num_process):
    process = Process(target=squared_number)
    process.append(process)
for process in processes:
    process.start()
for process in processes:
    process.join()

# MultiProcessing share data for one value
from multiprocessing import Process, Value, Array
import os
def squared_Number():
    for i in range(1000):
        i * i
if __name__ == "__main__":
    shared_number = Value('i',1)
    print("Number at starting point is ", shared_number.value) # 1
    
Beispiel #2
0
        cf = str(f.get())
        for g in q.get():
            percentage = g['percentage_probability']
            x1 = g['box_points'][0]
            y1 = g['box_points'][1]
            x2 = g['box_points'][2]
            y2 = g['box_points'][3]
            if percentage > 70:
                # print(x)
                xc = (x1 + x2) / 2
                yc = (y1 + y2) / 2
                # print("center x: ", xc.__str__(), " -  y: " + yc.__str__())
                if cf in centroids.keys():
                    p = centroids[cf]['points']

                    p.append(Point(xc, yc, percentage, int(cf)))
                else:
                    centroids[cf] = {
                        'points': [Point(xc, yc, percentage, int(cf))]
                    }

        if centroids.__len__() > 3:
            rf = str(int(cf) - 3)
            centroids.pop(rf)

        cs = centroids[cf]['points']
        if centroids.__len__() > 2:
            cs_pre = centroids[str(int(cf) - 1)]['points']
            for p in cs_pre:
                counter = 1
                found = False
import sys
from multiprocessing import Process


def EchoSever(client,addr):
    while 1:
        data = client.recv(1024)
        if data:
            client.send(data)
        else:
            client.close()
            return

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind(('0.0.0.0',int(sys.argv[1]))
s.listen(2)
threads=[]

while 1:
    client,addr = s.accept()
    thread = Process(target = EchoServer, args = ((client,addr)))
    thread.start()
    thread.append(thread)
Beispiel #4
0
    while running == 1:
        cf = str(f.get())
        for g in q.get():
            percentage = g['percentage_probability']
            x1 = g['box_points'][0]
            y1 = g['box_points'][1]
            x2 = g['box_points'][2]
            y2 = g['box_points'][3]
            if percentage > 70:
                # print(x)
                xc = (x1 + x2) / 2
                yc = (y1 + y2) / 2
                # print("center x: ", xc.__str__(), " -  y: " + yc.__str__())
                if cf in centroids.keys():
                    p = centroids[cf]['points']
                    p.append(Point(xc, yc, percentage))
                else:
                    centroids[cf] = {'points': [Point(xc, yc, percentage)]}

        if centroids.__len__() > 3:
            rf = str(int(cf) - 3)
            centroids.pop(rf)

        cs = centroids[cf]['points']
        if centroids.__len__() > 2:
            cs_pre = centroids[str(int(cf) - 1)]['points']
            for p in cs_pre:
                found = False
                for c in cs:
                    close = distance(p.x, p.y, c.x, c.y)
                    if close < 15: