Last active
December 31, 2015 07:59
-
-
Save maliubiao/7957890 to your computer and use it in GitHub Desktop.
debugme.py
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
| #! /data/project/py/Python-2.7.3/python | |
| import signal | |
| import os | |
| import time | |
| path = "/data/project/py/Python-2.7.3/python" | |
| masterpid = os.getpid() | |
| breakonce = False | |
| def sigint_handler(signum, frame): | |
| global breakonce | |
| if not breakonce: | |
| breakonce = True | |
| if os.fork() == 0: | |
| signal.signal(signal.SIGINT, signal.SIG_IGN) | |
| os.system("gdb %s %s" % (path, masterpid)) | |
| print "gdb done, quit" | |
| exit(0) | |
| else: | |
| os.wait3(os.WNOHANG) | |
| print "received SIGINT, quit." | |
| exit(0) | |
| def gendata(data): | |
| for i in data: | |
| try: | |
| yield data | |
| except GeneratorExit: | |
| yield data | |
| def main(): | |
| signal.signal(signal.SIGINT, sigint_handler) | |
| while True: | |
| time.sleep(1) | |
| k = gendata("nice1234") | |
| k.next() | |
| try: | |
| k.close() | |
| except RuntimeError, err: | |
| #willbe generator ignored GeneratorExit | |
| print err | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment