Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(824)

Side by Side Diff: client/utils/subprocess42.py

Issue 1373133004: Fixes and add smoke test: hard timeout on isolated task. (Closed) Base URL: git@github.com:luci/luci-py.git@master
Patch Set: . Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/utils/logging_utils.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Swarming Authors. All rights reserved. 1 # Copyright 2013 The Swarming Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 that 2 # Use of this source code is governed under the Apache License, Version 2.0 that
3 # can be found in the LICENSE file. 3 # can be found in the LICENSE file.
4 4
5 """subprocess42 is the answer to life the universe and everything. 5 """subprocess42 is the answer to life the universe and everything.
6 6
7 It has the particularity of having a Popen implementation that can yield output 7 It has the particularity of having a Popen implementation that can yield output
8 as it is produced while implementing a timeout and not requiring the use of 8 as it is produced while implementing a timeout and not requiring the use of
9 worker threads. 9 worker threads.
10 10
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 try: 447 try:
448 yield 448 yield
449 finally: 449 finally:
450 for sig, h in previous.iteritems(): 450 for sig, h in previous.iteritems():
451 signal.signal(sig, h) 451 signal.signal(sig, h)
452 452
453 453
454 @contextlib.contextmanager 454 @contextlib.contextmanager
455 def Popen_with_handler(args, **kwargs): 455 def Popen_with_handler(args, **kwargs):
456 proc = None 456 proc = None
457 def handler(_signum, _frame): 457 def handler(signum, _frame):
458 if proc: 458 if proc:
459 logging.info('Received signal %d; terminating', signum)
460 # There could be a race condition where the process already exited. Our
461 # subprocess implementation traps this.
459 proc.terminate() 462 proc.terminate()
460 463
461 with set_signal_handler(STOP_SIGNALS, handler): 464 with set_signal_handler(STOP_SIGNALS, handler):
462 proc = Popen(args, detached=True, **kwargs) 465 proc = Popen(args, detached=True, **kwargs)
463 try: 466 try:
464 yield proc 467 yield proc
465 finally: 468 finally:
466 proc.kill() 469 proc.kill()
OLDNEW
« no previous file with comments | « client/utils/logging_utils.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698