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

From: Nick Coghlan (ncoghlan_at_iinet.net.au)
Date: 12/31/04


Date: Fri, 31 Dec 2004 19:15:43 +1000
To: Python List <python-list@python.org>

Doran_Dermot@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@email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net


Relevant Pages

  • Re: threading priority
    ... >> GIL in order to execute, and the strategy for deciding which thread ... granularity on the rate of switching. ... threading implementation for the platform. ... pre-emption by the OS (because all other Python threads are waiting on ...
    (comp.lang.python)
  • Re: migrating mainframe z/VM Rexx to linux ooRexx
    ... as it is 40 times faster! ... Actually Gil and David have discussed making such a patch and ... the mother of invention" or more correctly "necessity being the mother ...
    (comp.lang.rexx)
  • Re: Python threads and Numeric/SciPy exploit Dual Core ?
    ... Excuse my lack of knowledge, ... > Simple Python code obviously cannot use the dual core by Python threads. ... as long as the binding releases the GIL, ...
    (comp.lang.python)
  • Re: Avoiding deadlocks in concurrent programming
    ... do you mean that python threads are always ... > are often blocked waiting for GIL? ... with no GIL, the queueing model is just as useful -- more, because ... a GIL avoids the same kind of concurrency problems in your application ...
    (comp.lang.python)
  • Re: Avoiding deadlocks in concurrent programming
    ... Please excuse my ignorance, do you mean that python threads are always ... are often blocked waiting for GIL? ...
    (comp.lang.python)