Codebase list python-procrunner / 238e835
Remove run(debug=...) Markus Gerstel 2 years ago
3 changed file(s) with 5 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
99 (those were deprecated in `#60 <https://github.com/DiamondLightSource/python-procrunner/pull/60>`_)
1010 * Calling the run() function with multiple unnamed arguments is no longer supported
1111 (previously deprecated in `#62 <https://github.com/DiamondLightSource/python-procrunner/pull/62>`_)
12 * The run() function no longer accepts a 'debug' argument
13 (previously deprecated in `#63 <https://github.com/DiamondLightSource/python-procrunner/pull/63>`_)
1214
1315 2.3.1 (2021-10-25)
1416 ------------------
303303 command,
304304 *,
305305 timeout: Optional[float] = None,
306 debug=None,
307306 stdin: Optional[bytes] = None,
308307 print_stdout: bool = True,
309308 print_stderr: bool = True,
323322
324323 :param array command: Command line to be run, specified as array.
325324 :param timeout: Terminate program execution after this many seconds.
326 :param boolean debug: Enable further debug messages. (deprecated)
327325 :param stdin: Optional bytestring that is passed to command stdin.
328326 :param boolean print_stdout: Pass stdout through to sys.stdout.
329327 :param boolean print_stderr: Pass stderr through to sys.stderr.
356354 else:
357355 assert sys.platform != "win32", "stdin argument not supported on Windows"
358356 stdin_pipe = subprocess.PIPE
359 if debug is not None:
360 warnings.warn(
361 "Use of the debug parameter is deprecated", DeprecationWarning, stacklevel=3
362 )
363357
364358 start_time = timeit.default_timer()
365359 if timeout is not None:
405399 stdout = _NonBlockingStreamReader(
406400 p.stdout,
407401 output=print_stdout,
408 debug=debug,
409402 notify=notifier.close,
410403 callback=callback_stdout,
411404 )
414407 stderr = _NonBlockingStreamReader(
415408 p.stderr,
416409 output=print_stderr,
417 debug=debug,
418410 notify=notifier.close,
419411 callback=callback_stderr,
420412 )
421413 if stdin is not None:
422414 notifyee, notifier = Pipe(False)
423415 thread_pipe_pool.append(notifyee)
424 _NonBlockingStreamWriter(
425 p.stdin, data=stdin, debug=debug, notify=notifier.close
426 )
416 _NonBlockingStreamWriter(p.stdin, data=stdin, notify=notifier.close)
427417
428418 timeout_encountered = False
429419
430420 while (p.returncode is None) and (
431421 (timeout is None) or (timeit.default_timer() < max_time)
432422 ):
433 if debug and timeout is not None:
434 logger.debug("still running (T%.2fs)", timeit.default_timer() - max_time)
435
436423 # wait for some time or until a stream is closed
437424 try:
438425 if thread_pipe_pool:
449436 if event:
450437 # One-shot, so remove stream and watch remaining streams
451438 thread_pipe_pool.pop(0)
452 if debug:
453 logger.debug("Event received from stream thread")
454439 else:
455440 time.sleep(0.5)
456441 except KeyboardInterrupt:
464449 if p.returncode is None:
465450 # timeout condition
466451 timeout_encountered = True
467 if debug:
468 logger.debug("timeout (T%.2fs)", timeit.default_timer() - max_time)
452 logger.debug("timeout (T%.2fs)", timeit.default_timer() - max_time)
469453
470454 # send terminate signal and wait some time for buffers to be read
471455 p.terminate()
2525
2626 with pytest.raises(RuntimeError):
2727 with pytest.warns(DeprecationWarning, match="timeout"):
28 procrunner.run(task, timeout=-1, debug=False)
28 procrunner.run(task, timeout=-1)
2929
3030 assert mock_subprocess.Popen.called
3131 assert mock_process.terminate.called
9494 mock.call(
9595 stream_stdout,
9696 output=mock.ANY,
97 debug=None,
9897 notify=mock.ANY,
9998 callback=mock.sentinel.callback_stdout,
10099 ),
101100 mock.call(
102101 stream_stderr,
103102 output=mock.ANY,
104 debug=None,
105103 notify=mock.ANY,
106104 callback=mock.sentinel.callback_stderr,
107105 ),
125123 with pytest.raises(NotImplementedError):
126124 procrunner.run([mock.Mock()], timeout=-1, raise_timeout_exception=True)
127125 assert mock_subprocess.Popen.call_args[1]["env"] == os.environ
128
129
130 @mock.patch("procrunner.subprocess")
131 def test_using_debug_parameter_raises_warning(mock_subprocess):
132 mock_subprocess.Popen.side_effect = NotImplementedError() # cut calls short
133 with pytest.warns(DeprecationWarning, match="debug"):
134 with pytest.raises(NotImplementedError):
135 procrunner.run([mock.Mock()], debug=True)
136 with pytest.warns(DeprecationWarning, match="debug"):
137 with pytest.raises(NotImplementedError):
138 procrunner.run([mock.Mock()], debug=False)
139126
140127
141128 @mock.patch("procrunner.subprocess")