Python process.Process() Examples
The following are 22
code examples of process.Process().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
process
, or try the search function
.
Example #1
Source File: action_file.py From aristo-leaderboard with Apache License 2.0 | 6 votes |
def summarize(self) -> Dict[int, ProcessSummary]: summary_by_process_id = dict() # type: Dict[int, ProcessSummary] for process_id in self.locations.keys(): locations = self.locations[process_id] actions = self.actions[process_id] p = Process(process_id=process_id, locations=locations, actions=actions, num_steps=self.num_sentences[process_id]) summary_by_process_id[p.process_id] = ProcessSummary( process_id=p.process_id, inputs=p.inputs(), outputs=p.outputs(), conversions=p.conversions(), moves=p.moves(), ) return summary_by_process_id
Example #2
Source File: action_file.py From aristo-leaderboard with Apache License 2.0 | 6 votes |
def diff_participants(self, other: "ActionFile") -> List[str]: report: List[str] = [] for process_id in self.process_ids(): self_participants = self.participants(process_id) if not other.has_process_id(process_id): report.append(f"Process {process_id} missing in {other.filename}") continue other_participants = other.participants(process_id) process_report: List[str] = [] for p in self_participants: if p not in other_participants: process_report.append(f"Process {process_id} in {other.filename}: participant \"{p}\" is missing.") for op in other_participants: if op not in self_participants: process_report.append( f"Process {process_id} in {other.filename}: participant \"{op}\" is unexpected.") report += sorted(process_report) return report
Example #3
Source File: window.py From OpenXMolar with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, hWnd = None, process = None, thread = None): """ @type hWnd: int or L{win32.HWND} @param hWnd: Window handle. @type process: L{Process} @param process: (Optional) Process that owns this window. @type thread: L{Thread} @param thread: (Optional) Thread that owns this window. """ self.hWnd = hWnd self.dwProcessId = None self.dwThreadId = None self.set_process(process) self.set_thread(thread)
Example #4
Source File: window.py From OpenXMolar with BSD 3-Clause "New" or "Revised" License | 6 votes |
def set_process(self, process = None): """ Manually set the parent process. Use with care! @type process: L{Process} @param process: (Optional) Process object. Use C{None} to autodetect. """ if process is None: self.__process = None else: self.__load_Process_class() if not isinstance(process, Process): msg = "Parent process must be a Process instance, " msg += "got %s instead" % type(process) raise TypeError(msg) self.dwProcessId = process.get_pid() self.__process = process
Example #5
Source File: GUI.py From Heart-rate-measurement-using-camera with Apache License 2.0 | 5 votes |
def __init__(self): super(GUI,self).__init__() self.initUI() self.webcam = Webcam() self.video = Video() self.input = self.webcam self.dirname = "" print("Input: webcam") self.statusBar.showMessage("Input: webcam",5000) self.btnOpen.setEnabled(False) self.process = Process() self.status = False self.frame = np.zeros((10,10,3),np.uint8) #self.plot = np.zeros((10,10,3),np.uint8) self.bpm = 0
Example #6
Source File: posixbase.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def spawnProcess(self, processProtocol, executable, args=(), env={}, path=None, uid=None, gid=None, usePTY=0, childFDs=None): if platformType == 'posix': if usePTY: if childFDs is not None: raise ValueError("Using childFDs is not supported with usePTY=True.") return process.PTYProcess(self, executable, args, env, path, processProtocol, uid, gid, usePTY) else: return process.Process(self, executable, args, env, path, processProtocol, uid, gid, childFDs) elif platformType == "win32": if uid is not None or gid is not None: raise ValueError("The uid and gid parameters are not supported on Windows.") if usePTY: raise ValueError("The usePTY parameter is not supported on Windows.") if childFDs: raise ValueError("Customizing childFDs is not supported on Windows.") if win32process: from twisted.internet._dumbwin32proc import Process return Process(self, processProtocol, executable, args, env, path) else: raise NotImplementedError, "spawnProcess not available since pywin32 is not installed." else: raise NotImplementedError, "spawnProcess only available on Windows or POSIX." # IReactorUDP
Example #7
Source File: proactor.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def spawnProcess(self, processProtocol, executable, args=(), env={}, path=None, usePTY=0): """Spawn a process.""" return process.Process(self, processProtocol, executable, args, env, path)
Example #8
Source File: que.py From Phy-Net with Apache License 2.0 | 5 votes |
def enque_file(self, file_name): cmd_list = [line.rstrip('\n') for line in open(file_name)] for cmd in cmd_list: broken_up_cmd = cmd.split() self.pl.append(process.Process(broken_up_cmd))
Example #9
Source File: api.py From hae with MIT License | 5 votes |
def createProcess(self, encoding = None): return Process(self.window, encoding) # 套接字服务端
Example #10
Source File: debug.py From OpenXMolar with BSD 3-Clause "New" or "Revised" License | 5 votes |
def force_garbage_collection(bIgnoreExceptions = True): """ Close all Win32 handles the Python garbage collector failed to close. @type bIgnoreExceptions: bool @param bIgnoreExceptions: C{True} to ignore any exceptions that may be raised when detaching. """ try: import gc gc.collect() bRecollect = False for obj in list(gc.garbage): try: if isinstance(obj, win32.Handle): obj.close() elif isinstance(obj, Event): obj.debug = None elif isinstance(obj, Process): obj.clear() elif isinstance(obj, Thread): obj.set_process(None) obj.clear() elif isinstance(obj, Module): obj.set_process(None) elif isinstance(obj, Window): obj.set_process(None) else: continue gc.garbage.remove(obj) del obj bRecollect = True except Exception, e: if not bIgnoreExceptions: raise warnings.warn(str(e), RuntimeWarning) if bRecollect: gc.collect()
Example #11
Source File: debug.py From OpenXMolar with BSD 3-Clause "New" or "Revised" License | 5 votes |
def is_debugee_attached(self, dwProcessId): """ Determine if the debugger is attached to the given process. @see: L{is_debugee}, L{is_debugee_started} @type dwProcessId: int @param dwProcessId: Process global ID. @rtype: bool @return: C{True} if the given process is attached to this L{Debug} instance. """ return dwProcessId in self.__attachedDebugees
Example #12
Source File: debug.py From OpenXMolar with BSD 3-Clause "New" or "Revised" License | 5 votes |
def is_debugee_started(self, dwProcessId): """ Determine if the given process was started by the debugger. @see: L{is_debugee}, L{is_debugee_attached} @type dwProcessId: int @param dwProcessId: Process global ID. @rtype: bool @return: C{True} if the given process was started for debugging by this L{Debug} instance. """ return dwProcessId in self.__startedDebugees
Example #13
Source File: window.py From OpenXMolar with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __get_window(self, hWnd): """ User internally to get another Window from this one. It'll try to copy the parent Process and Thread references if possible. """ window = Window(hWnd) if window.get_pid() == self.get_pid(): window.set_process( self.get_process() ) if window.get_tid() == self.get_tid(): window.set_thread( self.get_thread() ) return window #------------------------------------------------------------------------------
Example #14
Source File: window.py From OpenXMolar with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_process(self): """ @rtype: L{Process} @return: Parent Process object. """ if self.__process is not None: return self.__process self.__load_Process_class() self.__process = Process(self.get_pid()) return self.__process
Example #15
Source File: window.py From OpenXMolar with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __load_Process_class(self): global Process # delayed import if Process is None: from process import Process
Example #16
Source File: debug.py From OpenXMolar with BSD 3-Clause "New" or "Revised" License | 4 votes |
def cont(self, event = None): """ Resumes execution after processing a debug event. @see: dispatch(), loop(), wait() @type event: L{Event} @param event: (Optional) Event object returned by L{wait}. @raise WindowsError: Raises an exception on error. """ # If no event object was given, use the last event. if event is None: event = self.lastEvent # Ignore dummy events. if not event: return # Get the event continue status information. dwProcessId = event.get_pid() dwThreadId = event.get_tid() dwContinueStatus = event.continueStatus # Check if the process is still being debugged. if self.is_debugee(dwProcessId): # Try to flush the instruction cache. try: if self.system.has_process(dwProcessId): aProcess = self.system.get_process(dwProcessId) else: aProcess = Process(dwProcessId) aProcess.flush_instruction_cache() except WindowsError: pass # XXX TODO # # Try to execute the UnhandledExceptionFilter for second chance # exceptions, at least when in hostile mode (in normal mode it # would be breaking compatibility, as users may actually expect # second chance exceptions to be raised again). # # Reportedly in Windows 7 (maybe in Vista too) this seems to be # happening already. In XP and below the UnhandledExceptionFilter # was never called for processes being debugged. # Continue execution of the debugee. win32.ContinueDebugEvent(dwProcessId, dwThreadId, dwContinueStatus) # If the event is the last event, forget it. if event == self.lastEvent: self.lastEvent = None
Example #17
Source File: debug.py From OpenXMolar with BSD 3-Clause "New" or "Revised" License | 4 votes |
def detach(self, dwProcessId, bIgnoreExceptions = False): """ Detaches from a process currently being debugged. @note: On Windows 2000 and below the process is killed. @see: L{attach}, L{detach_from_all} @type dwProcessId: int @param dwProcessId: Global ID of a process to detach from. @type bIgnoreExceptions: bool @param bIgnoreExceptions: C{True} to ignore any exceptions that may be raised when detaching. C{False} to stop and raise an exception when encountering an error. @raise WindowsError: Raises an exception on error, unless C{bIgnoreExceptions} is C{True}. """ # Keep a reference to the process. We'll need it later. try: aProcess = self.system.get_process(dwProcessId) except KeyError: aProcess = Process(dwProcessId) # Determine if there is support for detaching. # This check should only fail on Windows 2000 and older. try: win32.DebugActiveProcessStop can_detach = True except AttributeError: can_detach = False # Continue the last event before detaching. # XXX not sure about this... try: if can_detach and self.lastEvent and \ self.lastEvent.get_pid() == dwProcessId: self.cont(self.lastEvent) except Exception, e: if not bIgnoreExceptions: raise warnings.warn(str(e), RuntimeWarning) # Cleanup all data referring to the process.
Example #18
Source File: debug.py From OpenXMolar with BSD 3-Clause "New" or "Revised" License | 4 votes |
def kill(self, dwProcessId, bIgnoreExceptions = False): """ Kills a process currently being debugged. @see: L{detach} @type dwProcessId: int @param dwProcessId: Global ID of a process to kill. @type bIgnoreExceptions: bool @param bIgnoreExceptions: C{True} to ignore any exceptions that may be raised when killing the process. @raise WindowsError: Raises an exception on error, unless C{bIgnoreExceptions} is C{True}. """ # Keep a reference to the process. We'll need it later. try: aProcess = self.system.get_process(dwProcessId) except KeyError: aProcess = Process(dwProcessId) # Cleanup all data referring to the process. self.__cleanup_process(dwProcessId, bIgnoreExceptions = bIgnoreExceptions) # Kill the process. try: try: if self.is_debugee(dwProcessId): try: if aProcess.is_alive(): aProcess.suspend() finally: self.detach(dwProcessId, bIgnoreExceptions = bIgnoreExceptions) finally: aProcess.kill() except Exception, e: if not bIgnoreExceptions: raise warnings.warn(str(e), RuntimeWarning) # Cleanup what remains of the process data.
Example #19
Source File: debug.py From OpenXMolar with BSD 3-Clause "New" or "Revised" License | 4 votes |
def __cleanup_process(self, dwProcessId, bIgnoreExceptions = False): """ Perform the necessary cleanup of a process about to be killed or detached from. This private method is called by L{kill} and L{detach}. @type dwProcessId: int @param dwProcessId: Global ID of a process to kill. @type bIgnoreExceptions: bool @param bIgnoreExceptions: C{True} to ignore any exceptions that may be raised when killing the process. @raise WindowsError: Raises an exception on error, unless C{bIgnoreExceptions} is C{True}. """ # If the process is being debugged... if self.is_debugee(dwProcessId): # Make sure a Process object exists or the following calls fail. if not self.system.has_process(dwProcessId): aProcess = Process(dwProcessId) try: aProcess.get_handle() except WindowsError: pass # fails later on with more specific reason self.system._add_process(aProcess) # Erase all breakpoints in the process. try: self.erase_process_breakpoints(dwProcessId) except Exception, e: if not bIgnoreExceptions: raise warnings.warn(str(e), RuntimeWarning) # Stop tracing all threads in the process. try: self.stop_tracing_process(dwProcessId) except Exception, e: if not bIgnoreExceptions: raise warnings.warn(str(e), RuntimeWarning) # The process is no longer a debugee.
Example #20
Source File: debug.py From OpenXMolar with BSD 3-Clause "New" or "Revised" License | 4 votes |
def add_existing_session(self, dwProcessId, bStarted = False): """ Use this method only when for some reason the debugger's been attached to the target outside of WinAppDbg (for example when integrating with other tools). You don't normally need to call this method. Most users should call L{attach}, L{execv} or L{execl} instead. @type dwProcessId: int @param dwProcessId: Global process ID. @type bStarted: bool @param bStarted: C{True} if the process was started by the debugger, or C{False} if the process was attached to instead. @raise WindowsError: The target process does not exist, is not attached to the debugger anymore. """ # Register the process object with the snapshot. if not self.system.has_process(dwProcessId): aProcess = Process(dwProcessId) self.system._add_process(aProcess) else: aProcess = self.system.get_process(dwProcessId) # Test for debug privileges on the target process. # Raises WindowsException on error. aProcess.get_handle() # Register the process ID with the debugger. if bStarted: self.__attachedDebugees.add(dwProcessId) else: self.__startedDebugees.add(dwProcessId) # Match the system kill-on-exit flag to our own. self.__setSystemKillOnExitMode() # Scan the process threads and loaded modules. # This is prefered because the thread and library events do not # properly give some information, like the filename for each module. aProcess.scan_threads() aProcess.scan_modules()
Example #21
Source File: test.py From FastPID with GNU Lesser General Public License v2.1 | 4 votes |
def randomtest(seed, steps, turns, pid, name, bits, sign) : random.seed(a=seed) results = numpy.array([]) results.resize((turns,)) outdir = 'randomtest-seed-{}'.format(seed) for test_num in range (turns) : kp = round(random.uniform(0, 255), 3) ki = round(random.uniform(0, kp), 3) kd = round(random.uniform(0, ki), 3) pid.configure(kp, ki, kd, bits, sign) reference = refpid.refpid(kp, ki, kd, bits, sign) ref = process.Process(reference, steps, turns) dut = process.Process(pid, steps, turns) ref.run() dut.run() # Check for fit errf = numpy.square(numpy.subtract(ref.output, dut.output)) err = numpy.cumsum(errf) / numpy.arange(1, ref.output.size+1, dtype=float) chi2 = numpy.sum(errf) / ref.output.size results[test_num,] = chi2 if chi2 > 1000 : if not os.path.isdir(outdir) : os.mkdir(outdir) outfile = os.path.join(outdir, "{}-p{}-i{}-d{}.png".format(name, kp, ki, kd)) setline = plt.plot(ref.setpoint, '', label='Setpoint') refline = plt.plot(ref.output, '', label='Reference') outline = plt.plot(dut.output, '', label='Output/Feedback') plt.legend(['Setpoint', 'Reference', 'Out/Feedback']) plt.xlabel('Time (Seconds)') plt.ylabel('Codes') plt.title('{} vs. Reference (p={} i={} d={})'.format(name, kp, ki, kd)) plt.savefig(outfile) plt.close() best = numpy.amin(results) worst = numpy.amax(results) med = numpy.median(results) print ("Best: {} Worst: {} Median: {}".format(best,worst,med)) plt.hist(results) outfile = os.path.join(outdir, "{}-histogram.png".format(name)) plt.savefig(outfile) plt.show()
Example #22
Source File: test_process.py From aristo-leaderboard with Apache License 2.0 | 4 votes |
def test_qa(self): p = Process( process_id=514, locations=OrderedDict([ ('glacier', [NO_LOC, NO_LOC, NO_LOC, NO_LOC, NO_LOC, NO_LOC, 'area', 'area']), ('snow', ['area', 'area', 'area', 'area', NO_LOC, NO_LOC, NO_LOC, NO_LOC]), ('mass', [NO_LOC, NO_LOC, NO_LOC, NO_LOC, NO_LOC, 'area', 'area', 'area']) ]), actions=OrderedDict([ ('glacier', [NO_ACT, NO_ACT, NO_ACT, NO_ACT, NO_ACT, CREATE, NO_ACT]), ('snow', [NO_ACT, NO_ACT, NO_ACT, DESTROY, NO_ACT, NO_ACT, NO_ACT]), ('mass', [NO_ACT, NO_ACT, NO_ACT, NO_ACT, CREATE, NO_ACT, NO_ACT]) ]), num_steps=7, ) self.assertEquals(p.inputs(), [ Input(participants='snow') ]) self.assertEquals(p.outputs(), [ Output(participants='glacier'), Output(participants='mass') ]) self.assertEquals(p.conversions(), [ Conversion(destroyed='snow', created='mass', locations='area', step_id='4') ]) self.assertEquals(p.moves(), []) p = Process( process_id=540, locations=OrderedDict([ ('air', ['unk', 'unk', 'unk', 'bronchiole', 'alveolus', 'unk', 'unk', 'unk', 'unk', 'unk', 'unk']), ('oxygen', ['unk', 'unk', 'unk', 'unk', 'unk', 'bloodstream', 'unk', 'unk', 'unk', 'unk', 'unk']), ('carbon dioxide', ['unk', 'unk', 'unk', 'unk', 'unk', 'bloodstream', 'bloodstream', 'alveolus', 'bronchiole', 'lung', 'body']) ]), actions=OrderedDict([ ('air', [NO_ACT, NO_ACT, MOVE, MOVE, MOVE, NO_ACT, NO_ACT, NO_ACT, NO_ACT, NO_ACT]), ('oxygen', [NO_ACT, NO_ACT, NO_ACT, NO_ACT, MOVE, MOVE, NO_ACT, NO_ACT, NO_ACT, NO_ACT]), ('carbon dioxide', [NO_ACT, NO_ACT, NO_ACT, NO_ACT, MOVE, NO_ACT, MOVE, MOVE, MOVE, MOVE]) ]), num_steps=10, ) self.assertEquals(p.inputs(), []) self.assertEquals(p.outputs(), []) self.assertEquals(p.conversions(), []) self.assertEquals(p.moves(), [ Move(participants='air', location_before='unk', location_after='bronchiole', step_id='3'), Move(participants='air', location_before='bronchiole', location_after='alveolus', step_id='4'), Move(participants='air', location_before='alveolus', location_after='unk', step_id='5'), Move(participants='oxygen', location_before='unk', location_after='bloodstream', step_id='5'), Move(participants='oxygen', location_before='bloodstream', location_after='unk', step_id='6'), Move(participants='carbon dioxide', location_before='unk', location_after='bloodstream', step_id='5'), Move(participants='carbon dioxide', location_before='bloodstream', location_after='alveolus', step_id='7'), Move(participants='carbon dioxide', location_before='alveolus', location_after='bronchiole', step_id='8'), Move(participants='carbon dioxide', location_before='bronchiole', location_after='lung', step_id='9'), Move(participants='carbon dioxide', location_before='lung', location_after='body', step_id='10'), ])