forked from notmyname/python_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeferred_fork.py
More file actions
41 lines (35 loc) · 731 Bytes
/
deferred_fork.py
File metadata and controls
41 lines (35 loc) · 731 Bytes
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
#!/usr/bin/env python2.4
from Common import *
import time
@deferred_fork
def long():
print 'starting long()'
time.sleep(10)
print 'long() finished'
return 'some important value'
@deferred_fork
def long2():
print 'starting long2()'
time.sleep(5)
raise Exception,'some error'
print 'long2() finished'
return 'long2() result'
print 'before calls'
x = long()
y = long2()
print 'after calls'
print 'something else'
time.sleep(2)
print 'done sleeping in main thread'
print 'waiting for long to finish'
x.end_now()
try:
print x()
except Exception,e:
print 'error: %s' % `e`
print 'waiting for long2 to finish'
try:
print y()
except Exception,e:
print 'error: %s' % e
print 'Done'