Is there a better way of listing Windows shares other than us ing "os.listdir"

Nick Coghlan ncoghlan at iinet.net.au
Fri Dec 31 04:15:43 EST 2004


Doran_Dermot at emc.com wrote:
> Hi David,
> 
> Thanks for the bit of code on finding shares!  I'd been using something a
> bit different (win32com.client stuff) but your code looks better. 
> 
> I've found that "win32file.FindFilesIterator" (suggested to me by another
> person on this mailing list) allows the gui to remain responsive. Using the
> same code to execute the "os.listdir" hangs the gui!

It's conceivable that os.listdir hangs on to the GIL while making the relevant 
system call. This would prevent any other Python threads from executing until 
the call was complete.

A check of the source code confirms that interpretation - listdir calls into the 
Python API as it constructs the list of names, so it needs to hold the GIL for 
those calls. It may be possible to modify the function so that the GIL isn't 
held during the system calls, but that would require a bit of work (given what a 
tangle of ifdef's the function is).

The relevant file is dist/src/Modules/posixmodule.c and the relevant function is 
posix_listdir.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list