def CollectorThread(stopEvent, file): win32trace.InitRead() handle = win32trace.GetHandle() # Run this thread at a lower priority to the main message-loop (and printing output) # thread can keep up import win32process win32process.SetThreadPriority( win32api.GetCurrentThread(), win32process.THREAD_PRIORITY_BELOW_NORMAL ) try: while 1: rc = win32event.WaitForMultipleObjects( (handle, stopEvent), 0, win32event.INFINITE ) if rc == win32event.WAIT_OBJECT_0: # About the only char we can't live with is \0! file.write(win32trace.read().replace("\0", "<null>")) else: # Stop event break finally: win32trace.TermRead() print("Thread dieing")
def setPriority(self, pid=None, priority=2): """ Set The Priority of a Windows Process. Priority is a value between 0-5 where 2 is normal priority. Default sets the priority of the current python process but can take any valid process ID. """ import win32api, win32process, win32con priorityClasses = [ win32process.IDLE_PRIORITY_CLASS, win32process.BELOW_NORMAL_PRIORITY_CLASS, win32process.NORMAL_PRIORITY_CLASS, win32process.ABOVE_NORMAL_PRIORITY_CLASS, win32process.HIGH_PRIORITY_CLASS, win32process.REALTIME_PRIORITY_CLASS ] threadPriorities = [ win32process.THREAD_PRIORITY_IDLE, #win32process.THREAD_PRIORITY_ABOVE_IDLE, #win32process.THREAD_PRIORITY_LOWEST, win32process.THREAD_PRIORITY_BELOW_NORMAL, win32process.THREAD_PRIORITY_NORMAL, win32process.THREAD_PRIORITY_ABOVE_NORMAL, win32process.THREAD_PRIORITY_HIGHEST, win32process.THREAD_PRIORITY_TIME_CRITICAL ] pid = win32api.GetCurrentProcessId() tid = win32api.GetCurrentThread() handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, True, pid) win32process.SetPriorityClass(handle, priorityClasses[priority]) win32process.SetThreadPriority(tid, threadPriorities[priority]) if Config.get('performance', 'restrict_to_first_processor'): win32process.SetProcessAffinityMask(handle, 1)
def __init__(self): self._my_win = None self.is_initialized = False self._attributes_dict = { 'Units': 'deg', 'Color': dict(r=1, g=1, b=1), 'Direction': 270, 'NumberOfDots': 500, 'FieldShape': 'circle', 'FieldPosition': dict(x=0.0, y=0), 'FieldSize': 1, 'DotLife': 5, # number of frames for each dot to be drawn 'SignalDots': 'same', # are the signal dots the 'same' on each frame? (see Scase et al) 'NoiseDots': 'direction', # do the noise dots follow random- 'walk', 'direction', or 'position' 'Speed': 0.01, 'Coherence': 0.9, 'RenderTime': 1, 'RenderFrequency': 60 } self.data = None # type: Dict[String, Any] self.experiment_data = None # type: ExperimentData win32process.SetThreadPriority(win32api.GetCurrentThread(), win32process.THREAD_PRIORITY_HIGHEST) pass
def __init__(self): self._x_values = None # type: list[int] self._y_values = None # type: list[int] self._y_trials_count = None # type: list[int] self._y_trials_correct_response_count = None # type: list[int] win32process.SetThreadPriority(win32api.GetCurrentThread(), win32process.THREAD_PRIORITY_LOWEST) pass
def after_function(self): # print('aaa') win32process.SetThreadPriority(win32api.GetCurrentThread(), win32process.THREAD_PRIORITY_LOWEST) while not self.gui_queue.empty(): name_status = self.gui_queue.get() if name_status[0] == 'enable_start_btn': self.btn_start_experiment.config(state='disabled' if name_status[1] is False else 'normal') tkinter.messagebox.showinfo('Information', 'Experiment ended succesfully !!!!') self.combobox_user_name_list.set('') self.root.after(100, self.after_function) pass
def render(self, data): win32process.SetThreadPriority(win32api.GetCurrentThread(), win32process.THREAD_PRIORITY_HIGHEST) self.data = data dot_patch = visual.WrappingDotStimOriginal( win=self._my_win, units=self.data['Units'], color=list([ eval(self.data['Color'])[0], eval(self.data['Color'])[1], eval(self.data['Color'])[2], ]), dir=self.convert_to_psycho_direction(self.data['Direction']), # density=self.data['DotsDensity'], nDots=self.density_to_number_of_dots(self.data['DotsDensity'], self.data['FieldSize'], self.data['FieldShape']), fieldShape=self.data['FieldShape'], fieldPos=[ eval(self.data['FieldPosition'])[0], eval(self.data['FieldPosition'])[1] ], fieldSize=self.data['FieldSize'], dotLife=self.data['DotLife'], # number of frames for each dot to be drawn signalDots=self.data['SignalDots'], # are the signal dots the 'same' on each frame? (see Scase et al) noiseDots=self.data['NoiseDots'], # do the noise dots follow random- 'walk', 'direction', or 'position' the # speed in the wrappingDotStim is per frame but in the user input it is in # seconds. speed=self.data['Speed'] / self.data['RenderFrequency'], coherence=self.data['Coherence']) if self.experiment_data.draw_fixation_point: fixation_point_stim = visual.Circle(win=self._my_win, radius=0.01, edges=32, pos=[0, 0], lineColor=[0, 1, 0], fillColor=[0, 1, 0]) start_time = time.time() while time.time() - start_time < self.data['RenderTime']: dot_patch.draw() if self.experiment_data.draw_fixation_point: fixation_point_stim.draw() self._my_win.flip() # redraw the buffer time.sleep((1 / self.data['RenderFrequency']))
def listening_function_thread(self, control_loop_queue): win32process.SetThreadPriority(win32api.GetCurrentThread(), win32process.THREAD_PRIORITY_LOWEST) while True: if not control_loop_queue.empty(): (command_function, command_data) = control_loop_queue.get() if command_function == 'update_graph': self.update_graph(command_data) elif command_function == 'reset_graph': self.reset_graph(command_data) elif command_function == 'init_graph': self.init_graph(command_data) pyplot.pause(0.1) time.sleep(0.5) pass
def __init__(self, graph_maker_command_queue): self.tkFileDialog = None self.protocol_reader = None # type: ProtocolReader self.protocol_writer = None # type:ProtocolWriter self.control_loop = None # type: ControlLoop self.root = None # type: Tk self.protocol_file_path = 'D:\RDK-protocols\coherence.xlsx' self.label_choose_folder = None # type: Label self.btn_choose_folder = None # type: Button self.protocol_root_dir = 'D:\RDK-protocols' # type: object self.combobox_protocol_list = None # type: Combobox self.btn_start_experiment = None # type: Button self.btn_stop_experiment = None # type: Button self.dynamic_controls_dict = None # type: Dict[Any, Any] self.parameters_attributes_dictionary = None # type: Dict[Any,Any] self.label_num_of_repetitions = None # type: Label self.label_num_of_trials = None # type: Label self.label_backward_error_probability: Label self.label_forward_rightward_probability: Label self.entry_num_of_repetitions = None # type: Entry self.entry_num_of_trials = None # type: Entry self.control_loop_thread = None # type: Thread self.current_gui_tooltip_window = None # type: Toplevel self.checkbox_confidence_choice = None # type:Checkbutton self.confidence_choice_value = None # type: BooleanVar self.draw_fixation_point_value = None # type:BooleanVar self.label_save_protocol_name = None # type: Label self.entry_save_protocol_name = None # type: Entry self.combobox_user_name_list = None # type: Combobox self.label_user_name = None # type: Label self.gui_queue = queue.Queue() self.control_loop_queue = queue.Queue() self.graph_maker_command_queue = graph_maker_command_queue self.btn_save_protocol = None # type: Button self.label_screen_height_size = None # type:Label self.label_screen_width_size = None # type:Label self.entry_screen_width_size = None # type: Button self.entry_screen_height_size = None # type: Button win32process.SetThreadPriority(win32api.GetCurrentThread(), win32process.THREAD_PRIORITY_NORMAL)
def thread_target(h, progress): try: self.progress = progress self.seen_finished = False self.running = True # Drop my thread priority, so outlook can keep repainting # and doing its stuff without getting stressed. import win32process, win32api THREAD_PRIORITY_BELOW_NORMAL = -1 win32process.SetThreadPriority( win32api.GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL) self.func(self.window.manager, self.window.config, progress) finally: try: win32api.PostMessage(h, MYWM_FINISHED, self.progress.stop_requested()) except win32api.error: # Bad window handle - already down. pass self.running = False self.progress = None
lockfile = open(LOCKFILE, "a") try: plock.lock(lockfile, plock.LOCK_EX | plock.LOCK_NB) except IOError: eclient.log("error: another_enigma-client_process_is_already_using_this_directory") sys.exit(1) win32process.SetPriorityClass( win32process.GetCurrentProcess(), win32process.IDLE_PRIORITY_CLASS ) win32process.SetThreadPriority( win32api.GetCurrentThread(), win32process.THREAD_PRIORITY_IDLE ) while 1: retval = os.system(cmdline) if retval == 0: eclient.log("submitting results ...") eclient.submit_chunk(server) eclient.log("success: submitted results") chunk = eclient.filereadlines('00hc.resume') if chunk is not None: eclient.log(''.join(("best result: ", chunk[1]))) eclient.log("trying to get workunit ...") eclient.get_chunk(server) eclient.log("success: got workunit")