Merge lp:~mbp/launchpad/882370-pidfile into lp:launchpad

Proposed by Martin Pool
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 14200
Proposed branch: lp:~mbp/launchpad/882370-pidfile
Merge into: lp:launchpad
Diff against target: 35 lines (+11/-2)
1 file modified
lib/canonical/lazr/doc/pidfile.txt (+11/-2)
To merge this branch: bzr merge lp:~mbp/launchpad/882370-pidfile
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+80536@code.launchpad.net

Commit message

[r=lifeless][bug=882370] Make pidfile doctest more robust

Description of the change

make another test perhaps less likely to fail because of timing issues, and perhaps more likely to explain what went wrong if it did fail

bug 882370

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/lazr/doc/pidfile.txt'
2--- lib/canonical/lazr/doc/pidfile.txt 2008-09-23 14:35:10 +0000
3+++ lib/canonical/lazr/doc/pidfile.txt 2011-10-27 04:52:27 +0000
4@@ -71,6 +71,7 @@
5 or SIGTERM, too. We'll demonstrate this with a couple of functions, because
6 we'll need them again later.
7
8+ >>> import errno
9 >>> import time
10 >>> subprocess_code = '''
11 ... import time
12@@ -92,13 +93,21 @@
13 ...
14 >>> def stop(pid, sig):
15 ... os.kill(pid, sig)
16- ... for i in range(20):
17+ ... for i in range(300):
18 ... if not os.path.exists(pidfile_path('nuts')):
19 ... print 'Stopped successfully'
20 ... break
21 ... time.sleep(0.1)
22 ... else:
23- ... print 'Error: pid file was not removed'
24+ ... try:
25+ ... # Is it still here at all?
26+ ... os.kill(pid, 0)
27+ ... except OSError, e:
28+ ... if e.errno == errno.ESRCH:
29+ ... print 'Error: pid file was not removed'
30+ ... else: raise
31+ ... else:
32+ ... print 'Error: process did not exit'
33 ...
34
35 Here's our example. We start, and then stop with SIGINT.