def __init__(self, fun, args, postprocess, job): """ Build multiprocessing queues and start worker. """ super(LongCalculation, self).__init__(job, "Cancel", 0, 0) self.setModal(True) self.input = Queue() self.output = Queue() self.input.put((fun, args, postprocess)) self.proc = Process(target=worker, args=(self.input, self.output)) self.proc.start() self.timer = QTimer() self.timer.timeout.connect(self.update) self.timer.start(10)
def main(): # To assign camera by name: put string(s) in list # Parse command line arguments parser = argparse.ArgumentParser(description='GUI for gaze tracking and pupillometry') parser.add_argument('-eye', dest='eye_file', type=str, help="Work with existing video recording, instead of live feed", default='') parser.add_argument('-world', dest='world_file', type=str, help="Work with existing video recording, instead of live feed", default='') args = parser.parse_args() # to use a pre-recorded video. # Use a string to specify the path to your video file as demonstrated below if args.eye_file == '': eye_src = ["UI154xLE-M", "USB Camera-B4.09.24.1", "FaceTime Camera (Built-in)", "Microsoft", "6000","Integrated Camera"] # to assign cameras directly, using integers as demonstrated below # eye_src = 1 else: # print "Using provide file: %s" % args.filename eye_src = args.eye_file if args.world_file == '': world_src = ["Logitech Camera","(046d:081d)","C510","B525", "C525","C615","C920","C930e"] # to assign cameras directly, using integers as demonstrated below # world_src = 0 else: world_src = args.world_file # Camera video size in pixels (width,height) eye_size = (260,216) #(1280,1024) world_size = (640,480) # on MacOS we will not use os.fork, elsewhere this does nothing. forking_enable(0) # Create and initialize IPC g_pool = Temp() g_pool.pupil_queue = Queue() g_pool.eye_rx, g_pool.eye_tx = Pipe(False) g_pool.quit = RawValue(c_bool,0) # this value will be substracted form the capture timestamp g_pool.timebase = RawValue(c_double,0) # make some constants avaiable g_pool.user_dir = user_dir g_pool.rec_dir = rec_dir g_pool.version = version g_pool.app = 'capture' # set up subprocesses p_eye = Process(target=eye, args=(g_pool,eye_src,eye_size)) # Spawn subprocess: p_eye.start() if platform.system() == 'Linux': # We need to give the camera driver some time before requesting another camera. sleep(0.5) world(g_pool,world_src,world_size) # Exit / clean-up p_eye.join()
def main(): # To assign camera by name: put string(s) in list eye_cam_names = [ "USB 2.0 Camera", "Microsoft", "6000", "Integrated Camera", "HD USB Camera" ] world_src = [ "Logitech Camera", "(046d:081d)", "C510", "B525", "C525", "C615", "C920", "C930e" ] eye_src = (eye_cam_names, 0), (eye_cam_names, 1 ) #first match for eye0 and second match for eye1 # to assign cameras directly, using integers as demonstrated below # eye_src = 4 , 5 #second arg will be ignored for monocular eye trackers # world_src = 1 # to use a pre-recorded video. # Use a string to specify the path to your video file as demonstrated below # eye_src = '/Users/mkassner/Downloads/000/eye0.mkv' , '/Users/mkassner/Downloads/eye.avi' # world_src = "/Users/mkassner/Downloads/000/world.mkv" # Camera video size in pixels (width,height) eye_size = (640, 480) world_size = (1280, 720) # on MacOS we will not use os.fork, elsewhere this does nothing. forking_enable(0) #g_pool holds variables. Only if added here they are shared across processes. g_pool = Global_Container() # Create and initialize IPC g_pool.pupil_queue = Queue() g_pool.quit = Value(c_bool, 0) g_pool.timebase = Value(c_double, 0) g_pool.eye_tx = [] # make some constants avaiable g_pool.user_dir = user_dir g_pool.version = get_version(version_file) g_pool.app = 'capture' g_pool.binocular = binocular p_eye = [] for eye_id in range(1 + 1 * binocular): rx, tx = Pipe(False) p_eye += [ Process(target=eye, args=(g_pool, eye_src[eye_id], eye_size, rx, eye_id)) ] g_pool.eye_tx += [tx] p_eye[-1].start() world(g_pool, world_src, world_size) # Exit / clean-up for p in p_eye: p.join()
def clone_with_timeout(src: str, dest: str, clone_func: Callable[[], None], timeout: float) -> None: """Clone a repository with timeout. Args: src: clone source dest: clone destination clone_func: callable that does the actual cloning timeout: timeout in seconds """ errors: Queue = Queue() process = Process(target=_clone_task, args=(clone_func, errors)) process.start() process.join(timeout) if process.is_alive(): process.terminate() # Give it literally a second (in successive steps of 0.1 second), # then kill it. # Can't use `process.join(1)` here, billiard appears to be bugged # https://github.com/celery/billiard/issues/270 killed = False for _ in range(10): time.sleep(0.1) if not process.is_alive(): break else: killed = True os.kill(process.pid, signal.SIGKILL) raise CloneTimeout(src, timeout, killed) if not errors.empty(): raise CloneFailure(src, dest, errors.get())
def main(): timePipe, sigPipe = Pipe() q = Queue() clock = Process(target=tickTock, args=(timePipe, )) testSignal = Process(target=signal, args=(q, sigPipe, [1])) testSignal.start() while True: print(q.get())
def init_marker_cacher(self): forking_enable(0) #for MacOs only from marker_detector_cacher import fill_cache visited_list = [False if x == False else True for x in self.cache] video_file_path = os.path.join(self.g_pool.rec_dir,'world.avi') self.cache_queue = Queue() self.cacher_seek_idx = Value(c_int,0) self.cacher_run = Value(c_bool,True) self.cacher = Process(target=fill_cache, args=(visited_list,video_file_path,self.cache_queue,self.cacher_seek_idx,self.cacher_run)) self.cacher.start()
def test_set_pdeathsig(self): success = "done" q = Queue() p = Process(target=parent_task, args=(q, success)) p.start() child_proc = psutil.Process(q.get(timeout=3)) try: p.terminate() assert q.get(timeout=3) == success finally: child_proc.terminate()
def init_marker_cacher(self): forking_enable(0) #for MacOs only from marker_detector_cacher import fill_cache visited_list = [False if x == False else True for x in self.cache] video_file_path = self.g_pool.capture.src timestamps = self.g_pool.capture.timestamps self.cache_queue = Queue() self.cacher_seek_idx = Value('i',0) self.cacher_run = Value(c_bool,True) self.cacher = Process(target=fill_cache, args=(visited_list,video_file_path,timestamps,self.cache_queue,self.cacher_seek_idx,self.cacher_run,self.min_marker_perimeter_cacher)) self.cacher.start()
def main(): q = Queue() x = [1, 2, 3, 4, 5] pl = [] for i in x: pl.append(Process(target=f, args=( q, i, ))) for p in pl: p.start() p.join() for i in x: print(q.get())
def main(): # To assign camera by name: put string(s) in list eye_src = ["Microsoft", "6000", "Integrated Camera"] world_src = [ "Logitech Camera", "(046d:081d)", "C510", "B525", "C525", "C615", "C920", "C930e" ] # to assign cameras directly, using integers as demonstrated below # eye_src = 1 # world_src = 0 # to use a pre-recorded video. # Use a string to specify the path to your video file as demonstrated below # eye_src = '/Users/mkassner/Pupil/datasets/p1-left/frames/test.avi' # world_src = "/Users/mkassner/Desktop/2014_01_21/000/world.avi" # Camera video size in pixels (width,height) eye_size = (640, 360) world_size = (1280, 720) # on MacOS we will not use os.fork, elsewhere this does nothing. forking_enable(0) # Create and initialize IPC g_pool = Temp() g_pool.pupil_queue = Queue() g_pool.eye_rx, g_pool.eye_tx = Pipe(False) g_pool.quit = RawValue(c_bool, 0) # this value will be substracted form the capture timestamp g_pool.timebase = RawValue(c_double, 0) # make some constants avaiable g_pool.user_dir = user_dir g_pool.rec_dir = rec_dir g_pool.version = version g_pool.app = 'capture' # set up subprocesses p_eye = Process(target=eye, args=(g_pool, eye_src, eye_size)) # Spawn subprocess: p_eye.start() if platform.system() == 'Linux': # We need to give the camera driver some time before requesting another camera. sleep(0.5) world(g_pool, world_src, world_size) # Exit / clean-up p_eye.join()
def run_in_childprocess(target, codec=None, *args, **kwargs): assert codec is None or len(codec) == 2, codec queue = Queue() p = Process(target=_wrapper, args=(target, codec, queue, args, kwargs)) p.start() e, r = queue.get() p.join() if e: raise e if codec: r = codec[1](r) return r
def main(): #IPC pupil_queue = Queue() timebase = Value(c_double, 0) cmd_world_end, cmd_launcher_end = Pipe() com0 = Pipe(True) eyes_are_alive = Value(c_bool, 0), Value(c_bool, 0) com1 = Pipe(True) com_world_ends = com0[0], com1[0] com_eye_ends = com0[1], com1[1] p_world = Process(target=world, args=(pupil_queue, timebase, cmd_world_end, com_world_ends, eyes_are_alive, user_dir, app_version, video_sources['world'])) p_world.start() while True: #block and listen for commands from world process. cmd = cmd_launcher_end.recv() if cmd == "Exit": break else: eye_id = cmd p_eye = Process(target=eye, args=(pupil_queue, timebase, com_eye_ends[eye_id], eyes_are_alive[eye_id], user_dir, app_version, eye_id, video_sources['eye%s' % eye_id])) p_eye.start() for p in active_children(): p.join() logger.debug('Laucher exit')
def output_monitor_queue(out): q = Queue() p = Process(target=enqueue_output, args=(out, q)) p.start() return q, p
from billiard import Process, Queue def f(q): q.put([42, None, 'hello']) if __name__ == '__main__': q = Queue() p = Process(target=f, args=(q, )) p.start() print(q.get()) # prints "[42, None, 'hello']" p.join()
def main(): # To assign camera by name: put string(s) in list world_src = [ "Pupil Cam1 ID2", "Logitech Camera", "(046d:081d)", "C510", "B525", "C525", "C615", "C920", "C930e" ] eye0 = [ "Pupil Cam1 ID0", "HD-6000", "Integrated Camera", "HD USB Camera", "USB 2.0 Camera" ] eye1 = ["Pupil Cam1 ID1", "HD-6000", "Integrated Camera"] eye_src = eye0, eye1 # to assign cameras directly, using integers as demonstrated below # eye_src = 1 , 1 #second arg will be ignored for monocular eye trackers # world_src = 0 # to use a pre-recorded video. # Use a string to specify the path to your video file as demonstrated below # eye_src = '/Users/mkassner/Downloads/eye0.mkv' , '/Users/mkassner/Downloads/eye.avi' # world_src = "/Users/mkassner/Downloads/000/world.mkv" # Default camera video size in pixels (width,height) eye_size = (640, 480) world_size = (1280, 720) # on MacOS we will not use os.fork, elsewhere this does nothing. forking_enable(0) #g_pool holds variables. Only if added here they are shared across processes. g_pool = Global_Container() # Create and initialize IPC g_pool.pupil_queue = Queue() g_pool.quit = Value(c_bool, 0) g_pool.timebase = Value(c_double, 0) g_pool.eye_tx = [] # make some constants avaiable g_pool.user_dir = user_dir g_pool.version = get_version(version_file) g_pool.app = 'capture' g_pool.binocular = binocular p_eye = [] for eye_id in range(1 + 1 * binocular): eye_end, world_end = Pipe(True) p_eye += [ Process(target=eye, args=(g_pool, eye_src[eye_id], eye_size, eye_end, eye_id)) ] p_eye[-1].start() #wait for ready message from eye to sequentialize startup logger.debug(world_end.recv()) g_pool.eye_tx += [world_end] world(g_pool, world_src, world_size) # Exit / clean-up for p in p_eye: p.join()
pages.append(new_url[:-5] + "_" + str(n) + ".html") return pages def scra_list_page(pages): ret = list() for page_url in pages: pq = PQ(url=page_url) ret.extend( re.findall( r"(?P<ip>\d+\.\d+\.\d+\.\d+)\:(?P<port>\d+)@(?P<pro>\w+)#", pq.text())) return ret queue = Queue() all = list() def test_proxy(): while 1: try: p = queue.get_nowait() except: break proxies = { p[2].lower(): '%s:%s' % (p[0], p[1]), } try: begin = time.time() code = requests.get("http://www.google.com.hk/",