[Tutor] os.listdir blocks threads?

Wolfgang Braun wolfgang.braun at gmx.de
Sat Oct 15 14:24:42 CEST 2005

Hello List,

I try to read large directories off network shares (samba3,NT) with
os.listdir(). The listdir() takes up to 5 minutes and blocks the rest of
the program (gui refreshes, ...)

The idea now is to put the listdir call into a separate thread so the
program can go on doing stuff (see below).

Unfortunately, as soon as I start a rdir instance the whole python
process locks up and waits for the os.listdir to return.

Plan b was to popen('/bin/ls -1 '%dir) in the rdir thread which works
better but is a bit kludgy (needs to work on NT, too) and the program
cannot be shudown cleanly unless the rdir thread has finished.

Obviously I'm doing something wrong? What would be the Right Way to
handle this situation?


# --- skeleton listdir in a thread

class rdir(threading.Thread):
    def __init__(self,dir,glob=None):

    def start(self):

    def run(self):
	    # alternatively os.popen(' /bin/ls -1U '%dir)
            # stuff to keep run() from returning

More information about the Tutor mailing list