Created
September 2, 2014 06:29
-
-
Save tianweidut/a5bcbd732da80640e447 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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