MCPcopy Create free account
hub / github.com/ipython/ipython / run

Method run

IPython/utils/_process_win32_controller.py:392–441  ·  view source on GitHub ↗

Runs the process, using the provided functions for I/O. The function stdin_func should return strings whenever a character or characters become available. The functions stdout_func and stderr_func are called whenever something is printed to stdout or stderr, respecti

(self, stdout_func = None, stdin_func = None, stderr_func = None)

Source from the content-addressed store, hash-verified

390 func(s.decode('utf_8', 'replace'))
391
392 def run(self, stdout_func = None, stdin_func = None, stderr_func = None):
393 """Runs the process, using the provided functions for I/O.
394
395 The function stdin_func should return strings whenever a
396 character or characters become available.
397 The functions stdout_func and stderr_func are called whenever
398 something is printed to stdout or stderr, respectively.
399 These functions are called from different threads (but not
400 concurrently, because of the GIL).
401 """
402 if stdout_func is None and stdin_func is None and stderr_func is None:
403 return self._run_stdio()
404
405 if stderr_func is not None and self.mergeout:
406 raise RuntimeError("Shell command was initiated with "
407 "merged stdin/stdout, but a separate stderr_func "
408 "was provided to the run() method")
409
410 # Create a thread for each input/output handle
411 stdin_thread = None
412 threads = []
413 if stdin_func:
414 stdin_thread = threading.Thread(target=self._stdin_thread,
415 args=(self.hstdin, self.piProcInfo.hProcess,
416 stdin_func, stdout_func))
417 threads.append(threading.Thread(target=self._stdout_thread,
418 args=(self.hstdout, stdout_func)))
419 if not self.mergeout:
420 if stderr_func is None:
421 stderr_func = stdout_func
422 threads.append(threading.Thread(target=self._stdout_thread,
423 args=(self.hstderr, stderr_func)))
424 # Start the I/O threads and the process
425 if ResumeThread(self.piProcInfo.hThread) == 0xFFFFFFFF:
426 raise ctypes.WinError()
427 if stdin_thread is not None:
428 stdin_thread.start()
429 for thread in threads:
430 thread.start()
431 # Wait for the process to complete
432 if WaitForSingleObject(self.piProcInfo.hProcess, INFINITE) == \
433 WAIT_FAILED:
434 raise ctypes.WinError()
435 # Wait for the I/O threads to complete
436 for thread in threads:
437 thread.join()
438
439 # Wait for the stdin thread to complete
440 if stdin_thread is not None:
441 stdin_thread.join()
442
443 def _stdin_raw_nonblock(self):
444 """Use the raw Win32 handle of sys.stdin to do non-blocking reads"""

Callers 4

_run_stdioMethod · 0.95
getoutputMethod · 0.45
getoutput_pexpectMethod · 0.45
systemFunction · 0.45

Calls 2

_run_stdioMethod · 0.95
startMethod · 0.45

Tested by

no test coverage detected