mirror of https://github.com/wanadev/yoga.git
Merge branch 'cancel-opti'
This commit is contained in:
commit
fc0c435453
|
@ -57,6 +57,7 @@ Changelog
|
|||
* **[NEXT]** (changes on ``master`` that have not been released yet):
|
||||
|
||||
* Python 2.7 support dropped
|
||||
* Allow to cancel an optimization using Ctrl+C (NOTE: this may not work on Windows)
|
||||
|
||||
* **1.0.0:**
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import os
|
||||
import sys
|
||||
import signal
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
from . import cli
|
||||
from . import image # noqa
|
||||
|
@ -9,14 +12,22 @@ def main(args=sys.argv[1:]):
|
|||
parser = cli.generate_main_cli()
|
||||
parsed_args = parser.parse_args(args if args else ["--help"])
|
||||
handler = getattr(sys.modules[__name__], parsed_args.subcommand)
|
||||
handler.optimize(
|
||||
parsed_args.input,
|
||||
parsed_args.output,
|
||||
options=vars(parsed_args),
|
||||
verbose=parsed_args.verbose,
|
||||
quiet=parsed_args.quiet,
|
||||
)
|
||||
with ThreadPoolExecutor(max_workers=1) as executor:
|
||||
executor.submit(
|
||||
handler.optimize,
|
||||
parsed_args.input,
|
||||
parsed_args.output,
|
||||
options=vars(parsed_args),
|
||||
verbose=parsed_args.verbose,
|
||||
quiet=parsed_args.quiet,
|
||||
)
|
||||
|
||||
|
||||
def _on_sigint_received(signalnum, stackframe):
|
||||
print("Optimization canceled")
|
||||
os.kill(os.getpid(), signal.SIGTERM)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
signal.signal(signal.SIGINT, _on_sigint_received)
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue