Normally these wouldĬome from user inputs (preferences, a database, whatever). join () print '*** Done'įirst, we establish some operating parameters. print '*** Main thread waiting' enclosure_queue. put ( enclosure ) # Now wait for the queue to be empty, indicating that we have # processed all of the downloads. get ( 'enclosures', ): print 'Queuing:', enclosure enclosure_queue. parse ( url, agent = 'fetch_podcasts.py' ) for entry in response : for enclosure in entry. for url in feed_urls : response = feedparser. start () # Download the feed(s) and put the enclosure URLs into # the queue. task_done () # Set up some threads to fetch the enclosures for i in range ( num_fetch_threads ): worker = Thread ( target = downloadEnclosures, args = ( i, enclosure_queue ,)) worker. get () print ' %s : Downloading:' % i, url # instead of really downloading the URL, # we just pretend and sleep time. """ while True : print ' %s : Looking for the next enclosure' % i url = q. These daemon threads go into an infinite loop, and only exit when the main thread ends. It processes items in the queue one after another. feed_urls = def downloadEnclosures ( i, q ): """This is the worker thread function. # System modules from Queue import Queue from threading import Thread import time # Local modules import feedparser # Set up some global variables num_fetch_threads = 2 enclosure_queue = Queue () # A real app wouldn't use hard-coded data.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |