Chapter 21: More Linux Programming

SIGINT Example , Page number: 669

In [ ]:
import signal, os

def sighandler ( signum,arg ):
    print ( "SIGINT received. Inside sighandler" ) 


signal.signal(signal.SIGINT,sighandler)
while ( 1 ):
    print  "Program Running"  

Handling Multiple Signals , Page number: 671

In [ ]:
import signal, os

def inthandler ( signum,arg ):
    print "SIGINT Received" 
    
def termhandler ( signum ,arg):
    print  "SIGTERM Received" 
    
def conthandler ( signum,arg ):
    print  "SIGCONT Received" 
    

signal.signal(signal.SIGINT,inthandler)
signal.signal(signal.SIGTERM,termhandler)
signal.signal(signal.SIGCONT,conthandler)

while ( 1 ):
    print  "Program Running" 

Registering A Common Handler , Page number: 673

In [ ]:
import signal, os

def sighandler ( signum ,arg):
    if(signum == SIGINT):
        print  "SIGINT Received" 
    elif(signum == SIGTERM):
        print  "SIGTERM Received" 
    elif(signum == SIGCONT):
        print  "SIGCONT Received" 

signal.signal(signal.SIGINT,sighandler)
signal.signal(signal.SIGTERM,sighandler)
signal.signal(signal.SIGCONT,sighandler)

while ( 1 ):
    print "Program running" 

Blocking Signals , Page number: 675

In [ ]:
import signal, os

def sighandler ( signum ,arg):
    if(signum == SIGINT):
        print  ("SIGINT Received") 
    elif(signum == SIGTERM):
        print  ("SIGTERM Received" )
    elif(signum == SIGCONT):
        print ( "SIGCONT Received" )

buffer = "\0"
signal.signal(signal.SIGINT,sighandler)
signal.signal(signal.SIGTERM,sighandler)
signal.signal(signal.SIGCONT,sighandler)

signal.pthread_sigmask(signal.SIG_BLOCK, [])

while ( buffer == "\0" ):
    buffer = input("Enter a string")
    print (buffer)
signal.pthread_sigmask(signal.SIG_UNBLOCK, [])
while(1):
    print("Program running")

Event Driven Programming , Page number: 678

In [ ]:
from tkinter import *


class Example(Frame):
        def __init__(self, parent):
            Frame.__init__(self, parent)

            self.display = Canvas(self, width=700, height=200)
            self.display.pack(side="top", fill="both", expand=True)
            
if __name__ == "__main__":
    root = Tk()
    root.title("Sample Window")
    Frame = Example(parent=root)
    Frame.pack(side="top", fill="both", expand=True)
    root.mainloop()

MyShapes , Page number: 681

In [ ]:
from tkinter import *


top = Tk()
top.title("Sample Window")
C = Canvas(top, height=500, width=500)
rcoor = 10,20,200,100
rect = C.create_rectangle(rcoor,fill="black")#rectangle
picoor = 250,0,350,100
pie = C.create_arc(picoor, start=300, extent=100, fill="black")#pie
pocoor = 250, 150, 250, 300, 300, 350, 400, 300, 320, 190
polygon = C.create_polygon(pocoor,fill="black")#polygon
C.pack()
top.mainloop()