Skip to content

Instantly share code, notes, and snippets.

@tianweidut
Created September 2, 2014 06:29
Show Gist options
  • Select an option

  • Save tianweidut/a5bcbd732da80640e447 to your computer and use it in GitHub Desktop.

Select an option

Save tianweidut/a5bcbd732da80640e447 to your computer and use it in GitHub Desktop.
#coding: utf-8
import sys
from multiprocessing import Process, Pipe
import traceback
class SubprcessException(Exception):
pass
class Foo():
@staticmethod
def work():
1 / 0
print 'in work'
1 / 0
def child(p2):
try:
print 'in child'
Foo.work()
print 'ffff'
except:
print '0000000000000000000000000000000000000000000'
print traceback.format_exception(*sys.exc_info())
print '1111111111111111111111111111111111111111111'
print type(traceback.format_exception(*sys.exc_info()))
tb = "".join(traceback.format_exception(*sys.exc_info()))
p2.send(tb)
raise
finally:
p2.send('----finally----')
def main():
print '--s--'
p1, p2 = Pipe()
proc = Process(target=child,
args=(p2,))
proc.daemon = True
proc.start()
proc.join()
if proc.exitcode == 0:
print 'ok'
else:
exc_info = p1.recv()
print '-------------------'
print exc_info
#print p1.recv()
#raise SubprcessException(exc_info)
#import pdb; pdb.set_trace()
#print exc_info
print '--e--'
if __name__ == "__main__":
try:
main()
except Exception as e:
print '~~~~~~~~~~~~~~~~~~~'
print e
print '^^^^^^^^^^^^^---- tb'
traceback.print_exc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment