processes and threading when it is ready no other threading thread methods may be reimplementedalthough adding additional methods is fine examplea threaded find word program |in this subsection we will review the code for the grepword- py program this program does the same job as grepword- pyonly it delegates the work to multiple threads rather than to multiple processes it is illustrated schematically in figure one particularly interesting feature of the program is that it does not appear to use any locks at all this is possible because the only shared data is list of filesand for these we use the queue queue class what makes queue queue special is that it handles all the locking itself internallyso whenever we access it to add or remove itemswe can rely on the queue itself to serialize accesses in the context of threadingserializing access to data means ensuring that only one thread at time has access to the data another benefit of using queue queue is that we don' have to share out the work ourselveswe simply add items of work to the queue and leave the worker threads to pick up work whenever they are ready the queue queue class works on first infirst out (fifobasisthe queue module also provides queue lifoqueue for last infirst out (lifoaccessand queue priorityqueue which is given tuples such as the -tuple (priorityitem)with items with the lowest priority numbers being processed first all the queues can be created with maximum size setif the maximum size is reached the queue will block further attempts to add items until items have been removed we will look at the grepword- py program in three partsstarting with the complete main(functiondef main()optswordargs parse_options(filelist get_files(argsopts recursework_queue queue queue(for in range(opts count)number "{ }format( if opts debug else "worker worker(work_queuewordnumberworker daemon true worker start(for filename in filelistwork_queue put(filenamework_queue join(