Skip to content

Instantly share code, notes, and snippets.

@maliubiao
Last active December 31, 2015 07:59
Show Gist options
  • Select an option

  • Save maliubiao/7957890 to your computer and use it in GitHub Desktop.

Select an option

Save maliubiao/7957890 to your computer and use it in GitHub Desktop.
debugme.py
#! /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