Show More
@@ -1,83 +1,83 b'' | |||
|
1 | 1 | Dummy extension simulating unsafe long running command |
|
2 | 2 | $ cat > sleepext.py <<EOF |
|
3 | > import itertools | |
|
3 | 4 | > import time |
|
4 | > import itertools | |
|
5 | 5 | > |
|
6 | > from mercurial.i18n import _ | |
|
6 | 7 | > from mercurial import registrar |
|
7 | > from mercurial.i18n import _ | |
|
8 | 8 | > |
|
9 | 9 | > cmdtable = {} |
|
10 | 10 | > command = registrar.command(cmdtable) |
|
11 | 11 | > |
|
12 | 12 | > @command(b'sleep', [], _(b'TIME'), norepo=True) |
|
13 | 13 | > def sleep(ui, sleeptime=b"1", **opts): |
|
14 | 14 | > with ui.uninterruptable(): |
|
15 | 15 | > for _i in itertools.repeat(None, int(sleeptime)): |
|
16 | 16 | > time.sleep(1) |
|
17 | 17 | > ui.warn(b"end of unsafe operation\n") |
|
18 | 18 | > ui.warn(b"%s second(s) passed\n" % sleeptime) |
|
19 | 19 | > EOF |
|
20 | 20 | |
|
21 | 21 | Kludge to emulate timeout(1) which is not generally available. |
|
22 | 22 | $ cat > timeout.py <<EOF |
|
23 | 23 | > from __future__ import print_function |
|
24 | 24 | > import argparse |
|
25 | 25 | > import signal |
|
26 | 26 | > import subprocess |
|
27 | 27 | > import sys |
|
28 | 28 | > import time |
|
29 | 29 | > |
|
30 | 30 | > ap = argparse.ArgumentParser() |
|
31 | 31 | > ap.add_argument('-s', nargs=1, default='SIGTERM') |
|
32 | 32 | > ap.add_argument('duration', nargs=1, type=int) |
|
33 | 33 | > ap.add_argument('argv', nargs='*') |
|
34 | 34 | > opts = ap.parse_args() |
|
35 | 35 | > try: |
|
36 | 36 | > sig = int(opts.s[0]) |
|
37 | 37 | > except ValueError: |
|
38 | 38 | > sname = opts.s[0] |
|
39 | 39 | > if not sname.startswith('SIG'): |
|
40 | 40 | > sname = 'SIG' + sname |
|
41 | 41 | > sig = getattr(signal, sname) |
|
42 | 42 | > proc = subprocess.Popen(opts.argv) |
|
43 | 43 | > time.sleep(opts.duration[0]) |
|
44 | 44 | > proc.poll() |
|
45 | 45 | > if proc.returncode is None: |
|
46 | 46 | > proc.send_signal(sig) |
|
47 | 47 | > proc.wait() |
|
48 | 48 | > sys.exit(124) |
|
49 | 49 | > EOF |
|
50 | 50 | |
|
51 | 51 | Set up repository |
|
52 | 52 | $ hg init repo |
|
53 | 53 | $ cd repo |
|
54 | 54 | $ cat >> $HGRCPATH << EOF |
|
55 | 55 | > [extensions] |
|
56 | 56 | > sleepext = ../sleepext.py |
|
57 | 57 | > EOF |
|
58 | 58 | |
|
59 | 59 | Test ctrl-c |
|
60 | 60 | $ python $TESTTMP/timeout.py -s INT 1 hg sleep 2 |
|
61 | 61 | interrupted! |
|
62 | 62 | [124] |
|
63 | 63 | |
|
64 | 64 | $ cat >> $HGRCPATH << EOF |
|
65 | 65 | > [experimental] |
|
66 | 66 | > nointerrupt = yes |
|
67 | 67 | > EOF |
|
68 | 68 | |
|
69 | 69 | $ python $TESTTMP/timeout.py -s INT 1 hg sleep 2 |
|
70 | 70 | interrupted! |
|
71 | 71 | [124] |
|
72 | 72 | |
|
73 | 73 | $ cat >> $HGRCPATH << EOF |
|
74 | 74 | > [experimental] |
|
75 | 75 | > nointerrupt-interactiveonly = False |
|
76 | 76 | > EOF |
|
77 | 77 | |
|
78 | 78 | $ python $TESTTMP/timeout.py -s INT 1 hg sleep 2 |
|
79 | 79 | shutting down cleanly |
|
80 | 80 | press ^C again to terminate immediately (dangerous) |
|
81 | 81 | end of unsafe operation |
|
82 | 82 | interrupted! |
|
83 | 83 | [124] |
General Comments 0
You need to be logged in to leave comments.
Login now