mirror of
https://github.com/docker/compose.git
synced 2025-07-21 12:44:54 +02:00
Fix signal handling with pyinstaller.
Raise a ShutdownException instead of a KeyboardInterupt when a thread.error is caught. This thread.error is only raised when run from a pyinstaller binary (for reasons unknown). Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
fc99c7ee19
commit
ed4473c849
@ -54,7 +54,7 @@ def main():
|
|||||||
try:
|
try:
|
||||||
command = TopLevelCommand()
|
command = TopLevelCommand()
|
||||||
command.sys_dispatch()
|
command.sys_dispatch()
|
||||||
except KeyboardInterrupt:
|
except (KeyboardInterrupt, signals.ShutdownException):
|
||||||
log.error("Aborting.")
|
log.error("Aborting.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except (UserError, NoSuchService, ConfigurationError) as e:
|
except (UserError, NoSuchService, ConfigurationError) as e:
|
||||||
|
@ -10,6 +10,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from queue import Queue, Empty # Python 3.x
|
from queue import Queue, Empty # Python 3.x
|
||||||
|
|
||||||
|
from compose.cli.signals import ShutdownException
|
||||||
|
|
||||||
STOP = object()
|
STOP = object()
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ class Multiplexer(object):
|
|||||||
pass
|
pass
|
||||||
# See https://github.com/docker/compose/issues/189
|
# See https://github.com/docker/compose/issues/189
|
||||||
except thread.error:
|
except thread.error:
|
||||||
raise KeyboardInterrupt()
|
raise ShutdownException()
|
||||||
|
|
||||||
def _init_readers(self):
|
def _init_readers(self):
|
||||||
for iterator in self.iterators:
|
for iterator in self.iterators:
|
||||||
|
@ -6,9 +6,11 @@ import sys
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from docker.errors import APIError
|
from docker.errors import APIError
|
||||||
|
from six.moves import _thread as thread
|
||||||
from six.moves.queue import Empty
|
from six.moves.queue import Empty
|
||||||
from six.moves.queue import Queue
|
from six.moves.queue import Queue
|
||||||
|
|
||||||
|
from compose.cli.signals import ShutdownException
|
||||||
from compose.utils import get_output_stream
|
from compose.utils import get_output_stream
|
||||||
|
|
||||||
|
|
||||||
@ -26,19 +28,7 @@ def parallel_execute(objects, func, index_func, msg):
|
|||||||
objects = list(objects)
|
objects = list(objects)
|
||||||
stream = get_output_stream(sys.stderr)
|
stream = get_output_stream(sys.stderr)
|
||||||
writer = ParallelStreamWriter(stream, msg)
|
writer = ParallelStreamWriter(stream, msg)
|
||||||
|
q = setup_queue(writer, objects, func, index_func)
|
||||||
for obj in objects:
|
|
||||||
writer.initialize(index_func(obj))
|
|
||||||
|
|
||||||
q = Queue()
|
|
||||||
|
|
||||||
# TODO: limit the number of threads #1828
|
|
||||||
for obj in objects:
|
|
||||||
t = Thread(
|
|
||||||
target=perform_operation,
|
|
||||||
args=(func, obj, q.put, index_func(obj)))
|
|
||||||
t.daemon = True
|
|
||||||
t.start()
|
|
||||||
|
|
||||||
done = 0
|
done = 0
|
||||||
errors = {}
|
errors = {}
|
||||||
@ -48,6 +38,9 @@ def parallel_execute(objects, func, index_func, msg):
|
|||||||
msg_index, result = q.get(timeout=1)
|
msg_index, result = q.get(timeout=1)
|
||||||
except Empty:
|
except Empty:
|
||||||
continue
|
continue
|
||||||
|
# See https://github.com/docker/compose/issues/189
|
||||||
|
except thread.error:
|
||||||
|
raise ShutdownException()
|
||||||
|
|
||||||
if isinstance(result, APIError):
|
if isinstance(result, APIError):
|
||||||
errors[msg_index] = "error", result.explanation
|
errors[msg_index] = "error", result.explanation
|
||||||
@ -68,6 +61,23 @@ def parallel_execute(objects, func, index_func, msg):
|
|||||||
raise error
|
raise error
|
||||||
|
|
||||||
|
|
||||||
|
def setup_queue(writer, objects, func, index_func):
|
||||||
|
for obj in objects:
|
||||||
|
writer.initialize(index_func(obj))
|
||||||
|
|
||||||
|
q = Queue()
|
||||||
|
|
||||||
|
# TODO: limit the number of threads #1828
|
||||||
|
for obj in objects:
|
||||||
|
t = Thread(
|
||||||
|
target=perform_operation,
|
||||||
|
args=(func, obj, q.put, index_func(obj)))
|
||||||
|
t.daemon = True
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
return q
|
||||||
|
|
||||||
|
|
||||||
class ParallelStreamWriter(object):
|
class ParallelStreamWriter(object):
|
||||||
"""Write out messages for operations happening in parallel.
|
"""Write out messages for operations happening in parallel.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user