summaryrefslogtreecommitdiff
path: root/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter24.ipynb
diff options
context:
space:
mode:
authorhardythe12015-07-03 12:23:43 +0530
committerhardythe12015-07-03 12:23:43 +0530
commit9d260e6fae7328d816a514130b691fbd0e9ef81d (patch)
tree9e6035702fca0f6f8c5d161de477985cacad7672 /C_Programming:_A_Modern_Approach_by_K.N._King/Chapter24.ipynb
parentafcd9e5397e3e1bde0392811d0482d76aac391dc (diff)
downloadPython-Textbook-Companions-9d260e6fae7328d816a514130b691fbd0e9ef81d.tar.gz
Python-Textbook-Companions-9d260e6fae7328d816a514130b691fbd0e9ef81d.tar.bz2
Python-Textbook-Companions-9d260e6fae7328d816a514130b691fbd0e9ef81d.zip
add/remove books
Diffstat (limited to 'C_Programming:_A_Modern_Approach_by_K.N._King/Chapter24.ipynb')
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter24.ipynb126
1 files changed, 126 insertions, 0 deletions
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter24.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter24.ipynb
new file mode 100755
index 00000000..05dd8488
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter24.ipynb
@@ -0,0 +1,126 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:70182e1ed50aea78649f1bef2946ce2b6e335126b84963ba06fce0660ac72886"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 24: Error Handling"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tsignal.c, Page 634"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import signal\n",
+ "import sys\n",
+ "def handler(sig,frame):\n",
+ " print \"Handler called for signal\",sig\n",
+ "print \"Installing handler for signal\", signal.SIGINT\n",
+ "orig_handler=signal.signal(signal.SIGINT,handler)\n",
+ "print \"Changing handler to SIG_IGN\"\n",
+ "signal.signal(signal.SIGINT,signal.SIG_IGN)\n",
+ "print \"Restoring original handler\"\n",
+ "signal.signal(signal.SIGINT,orig_handler)\n",
+ "print \"Program terminates normally\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Installing handler for signal 2\n",
+ "Changing handler to SIG_IGN\n",
+ "Restoring original handler\n",
+ "Program terminates normally\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example tsetjmp.c, Page 636"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def main():\n",
+ " def f1():\n",
+ " print \"f1 begins\"\n",
+ " f2()\n",
+ " return\n",
+ " print \"f1 returns\"\n",
+ "\n",
+ " def f2():\n",
+ " print \"f2 begins\"\n",
+ " #longjmp(env, 1)\n",
+ " setjmp=1\n",
+ " print \"Program terminates: longjmp called\"\n",
+ " return\n",
+ " print \"f2 returns\"\n",
+ "\n",
+ " setjmp=0\n",
+ " if (setjmp == 0):\n",
+ " print \"setjmp returned 0\"\n",
+ " else:\n",
+ " print \"Program terminates: longjmp called\"\n",
+ " f1()\n",
+ " return\n",
+ " print \"Program terminates normally\"\n",
+ " \n",
+ "if __name__=='__main__':\n",
+ " main()\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "setjmp returned 0\n",
+ "f1 begins\n",
+ "f2 begins\n",
+ "Program terminates: longjmp called\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file