{ "metadata": { "name": "chapter-21.ipynb" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "

Chapter 21: More Linux Programming

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

SIGINT Example , Page number: 669

" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "import signal, os\n", "\n", "def sighandler ( signum,arg ):\n", " print ( \"SIGINT received. Inside sighandler\" ) \n", "\n", "\n", "signal.signal(signal.SIGINT,sighandler)\n", "while ( 1 ):\n", " print \"Program Running\" \n" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Handling Multiple Signals , Page number: 671

" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "import signal, os\n", "\n", "def inthandler ( signum,arg ):\n", " print \"SIGINT Received\" \n", " \n", "def termhandler ( signum ,arg):\n", " print \"SIGTERM Received\" \n", " \n", "def conthandler ( signum,arg ):\n", " print \"SIGCONT Received\" \n", " \n", "\n", "signal.signal(signal.SIGINT,inthandler)\n", "signal.signal(signal.SIGTERM,termhandler)\n", "signal.signal(signal.SIGCONT,conthandler)\n", "\n", "while ( 1 ):\n", " print \"Program Running\" " ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Registering A Common Handler , Page number: 673

" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "import signal, os\n", "\n", "def sighandler ( signum ,arg):\n", " if(signum == SIGINT):\n", " print \"SIGINT Received\" \n", " elif(signum == SIGTERM):\n", " print \"SIGTERM Received\" \n", " elif(signum == SIGCONT):\n", " print \"SIGCONT Received\" \n", "\n", "signal.signal(signal.SIGINT,sighandler)\n", "signal.signal(signal.SIGTERM,sighandler)\n", "signal.signal(signal.SIGCONT,sighandler)\n", "\n", "while ( 1 ):\n", " print \"Program running\" \n" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Blocking Signals , Page number: 675

" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "import signal, os\n", "\n", "def sighandler ( signum ,arg):\n", " if(signum == SIGINT):\n", " print (\"SIGINT Received\") \n", " elif(signum == SIGTERM):\n", " print (\"SIGTERM Received\" )\n", " elif(signum == SIGCONT):\n", " print ( \"SIGCONT Received\" )\n", "\n", "buffer = \"\\0\"\n", "signal.signal(signal.SIGINT,sighandler)\n", "signal.signal(signal.SIGTERM,sighandler)\n", "signal.signal(signal.SIGCONT,sighandler)\n", "\n", "signal.pthread_sigmask(signal.SIG_BLOCK, [])\n", "\n", "while ( buffer == \"\\0\" ):\n", " buffer = input(\"Enter a string\")\n", " print (buffer)\n", "signal.pthread_sigmask(signal.SIG_UNBLOCK, [])\n", "while(1):\n", " print(\"Program running\")\n" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Event Driven Programming , Page number: 678

" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "from tkinter import *\n", "\n", "\n", "class Example(Frame):\n", " def __init__(self, parent):\n", " Frame.__init__(self, parent)\n", "\n", " self.display = Canvas(self, width=700, height=200)\n", " self.display.pack(side=\"top\", fill=\"both\", expand=True)\n", " \n", "if __name__ == \"__main__\":\n", " root = Tk()\n", " root.title(\"Sample Window\")\n", " Frame = Example(parent=root)\n", " Frame.pack(side=\"top\", fill=\"both\", expand=True)\n", " root.mainloop()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

MyShapes , Page number: 681

" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "from tkinter import *\n", "\n", "\n", "top = Tk()\n", "top.title(\"Sample Window\")\n", "C = Canvas(top, height=500, width=500)\n", "rcoor = 10,20,200,100\n", "rect = C.create_rectangle(rcoor,fill=\"black\")#rectangle\n", "picoor = 250,0,350,100\n", "pie = C.create_arc(picoor, start=300, extent=100, fill=\"black\")#pie\n", "pocoor = 250, 150, 250, 300, 300, 350, 400, 300, 320, 190\n", "polygon = C.create_polygon(pocoor,fill=\"black\")#polygon\n", "C.pack()\n", "top.mainloop()\n" ], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }