Software Design
Spring 2008

Lab Exercise 10

Due: never!!!

Threaders

  1. Download and read

    wget http://wb/sd/code/Threader.py
    
    Now run it. When you press the Make Threader button, it creates a Threader (which is a kind of Turtle). The Threader executes snowflake, which runs for a while, drawing a Koch snowflake.

  2. While the Threader is making the rounds, try pressing Make Threader again. Is the GUI responsive while snowflake is running? What does this tell you about the way the GUI is implemented in Tkinter?

  3. While the Threader is hard at work, press the Quit button. Does the program quit right away? Why not? Try hitting Control-C while it is running.

  4. Change make_threader so that when it invokes snowflake, it runs in a new Thread. Now run more than one Threader at a time. See the difference? Do all the Threaders run at the same speed? Why or why not?

  5. Unfortunately, you still can't quit while a Threader is running. To fix that:

    1. Add an attribute named running to Threader, and initialize it to 1.

    2. Change koch so that it checks running and quits if it is 0.

    3. Create a new kind of TurtleWorld called ThreaderWorld. Override quit so that when the user presses quit, it loops through all the Threaders and sets their running attribute to 0.

    It ain't pretty, but unfortunately you can't really kill another thread; you have to ask it to kill itself.

  6. Create a lot of Threaders. What happens? Why?