test: xkeyboard-config: handle keyboard interrupts correctly In python multiprocessing, each process needs to handle (and ignore) the KeyboardInterrupt to avoid exception logging. This is a separate patch for easier reviewing, the first hunks merely re-indent all of the xkbcommontool/xkbcomp functions into a try/except KeyboardInterrupt block. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
diff --git a/test/xkeyboard-config-test.py.in b/test/xkeyboard-config-test.py.in
index d4c2ccf..c271f5a 100755
--- a/test/xkeyboard-config-test.py.in
+++ b/test/xkeyboard-config-test.py.in
@@ -30,86 +30,92 @@ if os.isatty(sys.stdout.fileno()):
def xkbcommontool(rmlvo):
- r = rmlvo.get('r', 'evdev')
- m = rmlvo.get('m', 'pc105')
- l = rmlvo.get('l', 'us')
- v = rmlvo.get('v', None)
- o = rmlvo.get('o', None)
- args = [
- 'rmlvo-to-keymap',
- '--rules', r,
- '--model', m,
- '--layout', l,
- ]
- if v is not None:
- args += ['--variant', v]
- if o is not None:
- args += ['--options', o]
-
- success = True
- out = io.StringIO()
- if verbose:
- print(':: {}'.format(' '.join(args)), file=out)
-
try:
- output = subprocess.check_output(args, stderr=subprocess.STDOUT)
+ r = rmlvo.get('r', 'evdev')
+ m = rmlvo.get('m', 'pc105')
+ l = rmlvo.get('l', 'us')
+ v = rmlvo.get('v', None)
+ o = rmlvo.get('o', None)
+ args = [
+ 'rmlvo-to-keymap',
+ '--rules', r,
+ '--model', m,
+ '--layout', l,
+ ]
+ if v is not None:
+ args += ['--variant', v]
+ if o is not None:
+ args += ['--options', o]
+
+ success = True
+ out = io.StringIO()
if verbose:
- print(output.decode('utf-8'), file=out)
- except subprocess.CalledProcessError as err:
- print('ERROR: Failed to compile: {}'.format(' '.join(args)), file=out)
- print(err.output.decode('utf-8'), file=out)
- success = False
+ print(':: {}'.format(' '.join(args)), file=out)
+
+ try:
+ output = subprocess.check_output(args, stderr=subprocess.STDOUT)
+ if verbose:
+ print(output.decode('utf-8'), file=out)
+ except subprocess.CalledProcessError as err:
+ print('ERROR: Failed to compile: {}'.format(' '.join(args)), file=out)
+ print(err.output.decode('utf-8'), file=out)
+ success = False
- return success, out.getvalue()
+ return success, out.getvalue()
+ except KeyboardInterrupt:
+ pass
def xkbcomp(rmlvo):
- r = rmlvo.get('r', 'evdev')
- m = rmlvo.get('m', 'pc105')
- l = rmlvo.get('l', 'us')
- v = rmlvo.get('v', None)
- o = rmlvo.get('o', None)
- args = ['setxkbmap', '-print']
- if r is not None:
- args.append('-rules')
- args.append('{}'.format(r))
- if m is not None:
- args.append('-model')
- args.append('{}'.format(m))
- if l is not None:
- args.append('-layout')
- args.append('{}'.format(l))
- if o is not None:
- args.append('-option')
- args.append('{}'.format(o))
-
- success = True
- out = io.StringIO()
- if verbose:
- print(':: {}'.format(' '.join(args)), file=out)
-
try:
- xkbcomp_args = ['xkbcomp', '-xkb', '-', '-']
-
- setxkbmap = subprocess.Popen(args, stdout=subprocess.PIPE)
- xkbcomp = subprocess.Popen(xkbcomp_args, stdin=setxkbmap.stdout,
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- setxkbmap.stdout.close()
- stdout, stderr = xkbcomp.communicate()
- if xkbcomp.returncode != 0:
+ r = rmlvo.get('r', 'evdev')
+ m = rmlvo.get('m', 'pc105')
+ l = rmlvo.get('l', 'us')
+ v = rmlvo.get('v', None)
+ o = rmlvo.get('o', None)
+ args = ['setxkbmap', '-print']
+ if r is not None:
+ args.append('-rules')
+ args.append('{}'.format(r))
+ if m is not None:
+ args.append('-model')
+ args.append('{}'.format(m))
+ if l is not None:
+ args.append('-layout')
+ args.append('{}'.format(l))
+ if o is not None:
+ args.append('-option')
+ args.append('{}'.format(o))
+
+ success = True
+ out = io.StringIO()
+ if verbose:
+ print(':: {}'.format(' '.join(args)), file=out)
+
+ try:
+ xkbcomp_args = ['xkbcomp', '-xkb', '-', '-']
+
+ setxkbmap = subprocess.Popen(args, stdout=subprocess.PIPE)
+ xkbcomp = subprocess.Popen(xkbcomp_args, stdin=setxkbmap.stdout,
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ setxkbmap.stdout.close()
+ stdout, stderr = xkbcomp.communicate()
+ if xkbcomp.returncode != 0:
+ print('ERROR: Failed to compile: {}'.format(' '.join(args)), file=out)
+ success = False
+ if xkbcomp.returncode != 0 or verbose:
+ print(stdout.decode('utf-8'), file=out)
+ print(stderr.decode('utf-8'), file=out)
+
+ # This catches setxkbmap errors.
+ except subprocess.CalledProcessError as err:
print('ERROR: Failed to compile: {}'.format(' '.join(args)), file=out)
+ print(err.output.decode('utf-8'), file=out)
success = False
- if xkbcomp.returncode != 0 or verbose:
- print(stdout.decode('utf-8'), file=out)
- print(stderr.decode('utf-8'), file=out)
- # This catches setxkbmap errors.
- except subprocess.CalledProcessError as err:
- print('ERROR: Failed to compile: {}'.format(' '.join(args)), file=out)
- print(err.output.decode('utf-8'), file=out)
- success = False
-
- return success, out.getvalue()
+ return success, out.getvalue()
+ except KeyboardInterrupt:
+ pass
def parse(path):
@@ -180,4 +186,7 @@ def main(args):
if __name__ == '__main__':
- main(sys.argv)
+ try:
+ main(sys.argv)
+ except KeyboardInterrupt:
+ print('Exiting after Ctrl+C')