Created
January 23, 2014 14:00
-
-
Save smit1678/8578833 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ThreadXML(threading.Thread): | |
def __init__(self, queue): | |
threading.Thread.__init__(self) | |
self.queue = queue | |
def run(self): | |
while True: | |
#grabs file from queue | |
fn = self.queue.get() | |
#grabs file and processes | |
xmlProcess(fn) | |
#signals to queue job is done | |
self.queue.task_done() | |
def main(): | |
#spawn a pool of threads, and pass them queue instance | |
for i in range(5): | |
t = ThreadXML(queue) | |
t.setDaemon(True) | |
t.start() | |
#populate queue with data | |
for fn in os.listdir('.'): | |
if fn.endswith(".xml"): | |
queue.put(fn) | |
#wait on the queue until everything has been processed | |
queue.join() | |
main() | |
# credit: http://www.ibm.com/developerworks/aix/library/au-threadingpython/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment