ddaee9f060
Currently, when calling AsyncProcess.stop(), the code stops the stdout and stderr readers and kills the process. There exists an end case (as described in the bug report) in which after the readers have been stopped the sub-process will generate a substantial amount of outputs to either fd. Since the 'subprocess' module is launched with subprocess.PIPE as stdout/stderr, and since Linux's pipes can be filled to the point where writing new data to them will block, this may cause a deadlock if the sub-process has a signal handler for the signal (for example, the process is handling SIGTERM to produce a graceful exit of the program). Therefore, this patch proposes to only kill the readers until AFTER wait() returned and the process truly died. Also, relying on _kill_event had to cease since invoking its send() method caused a logical loop back to _kill, causing eventlet errors. A different possible solution is closing the stdout/stderr pipes. Alas, this may raise an exception in the sub-process ("what? No stdout?! Crash!") and defeats the 'graceful' part of the process. Closes-Bug: #1506021 Change-Id: I506c41c634a8d656d81a8ad7963412b834bdfa5b
27 lines
765 B
Python
27 lines
765 B
Python
# Copyright 2015 Red Hat, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import os
|
|
import sys
|
|
|
|
|
|
def main():
|
|
filename = sys.argv[1]
|
|
if not os.path.exists(filename):
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|