Beispiel #1
0
def send_over_time(per_sec, duration):
    print("Running {} per second over {} seconds on {}...".format(
        per_sec, duration, url))
    pool = []

    arg_headers = None
    arg_args = None

    print("Build pool...")
    for i in range(per_sec):
        #t = threading.Thread(target=make_req, args=[arg_headers, arg_args])
        t = multiprocessing.Process(
            target=make_req,
            args=[work_queue, time_queue, arg_headers, arg_args])
        pool.append(t)

    print("Start pool...")
    for p in pool:
        p.start()

    print("Running...")
    start_time = time.time()
    cur = time.time()
    next_block = cur + (1 / per_sec)
    end = cur + duration
    while cur < end:
        while cur >= next_block:
            work_queue.put(cur)
            next_block += (1 / per_sec)
        cur += time.time() - cur
        print(cur, end)

    # Finish.
    print("Halting queue...")
    for i in range(len(pool)):
        work_queue.put(None)
    work_queue.join()

    # Get results.
    print("Getting results...")
    sum_times = 0
    max_time = 0
    len_times = 0
    times = []
    while not time_queue.empty():
        occured_time, cur_time = time_queue.get()
        if cur_time > max_time:
            max_time = cur_time
        sum_times += cur_time
        len_times += 1
        times.append([occured_time - start_time, cur_time])
    print("\nMax Time: {}ms\nAvg Time: {}ms".format(
        round(max_time * 1000), round((sum_times / len_times) * 1000)))

    return times
Beispiel #2
0
    def run(self):
      pool = []
      for i in range(self.process_cnt):
        self.data += i
        p = multiprocessing.Process(target=self._process, args=(i,) )
        p.start()
        pool.append(p)

      for p in pool:
        p.join()

      while not self.queue.empty():
        d = self.queue.get()
        print(d)
Beispiel #3
0
def test_locked_print():
  def locked_print(lock, i):
    #with lock: 
    print('hello world', i)
    print('hello world', i+100)
    time.sleep(0.1) 
    print('hello world', i+200)
    print('hello world', i+300)

  l = multiprocessing.Lock()
  pool = []
  for i in range(50):
    p = multiprocessing.Process(target=locked_print, args=(l, i) )
    pool.append(p)
    p.start()
   
  for p in pool: 
    p.join()