[python-win32] GetFileVersionInfo blocks main thread

Rickey, Kyle W Kyle.Rickey at bakerhughes.com
Mon Apr 21 15:20:54 CEST 2008


Thanks Roger/Tim. In the mean time I'm going to check out the processing
module Tim pointed me to. Hopefully I'll have some free time to test it
out. Thanks again for your help.

-Kyle Rickey

-----Original Message-----
From: python-win32-bounces at python.org
[mailto:python-win32-bounces at python.org] On Behalf Of Roger Upole
Sent: Sunday, April 20, 2008 10:11 PM
To: python-win32 at python.org
Subject: [python-win32] GetFileVersionInfo blocks main thread

Kyle Rickey wrote:
> I'm trying to get the file version of an executable file on our
network.
> At times our network is quite slow, so to prevent blocking of my main
> application, I decided to put the code into a separate thread.
>
> Depending on the network speed, it can take up to 30 seconds to
return.
> This is because of a vpn connection etc.
>
> But when put in a separate thread, it will block the entire
application
> until the function returns. Take the following code for example:
>
> import threading, time, os, win32api
>
> file = r"\\network_share\file.exe"
>
> def get_version_number():
> if os.path.exists(file):
> info = win32api.GetFileVersionInfo(file, "\\")
> ms = info['FileVersionMS']
> ls = info['FileVersionLS']
> return win32api.HIWORD(ms), win32api.LOWORD(ms),
> win32api.HIWORD(ls), win32api.LOWORD(ls)
>
> def test():
> print ".".join([str(i) for i in get_version_number()])
>
> print "AA"
> threading.Thread(target=test).start()
> while 1:
> print "AA"
> time.sleep(0.5)
>
> The output looks like this:
>
> AA
> AA
> 2.0.0.15
> AA
> ..
>
> The problem is after those 1st to "AA"'s got printed, no more were
> printed until the version number came back. Any ideas why this is
> happening?
> I've got python 2.5 and pywin32-210.
>
> -Kyle Rickey

This function doesn't release the thread lock when making the API
calls.  I'll try to remedy this before the next release.

              Roger


_______________________________________________
python-win32 mailing list
python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32


More information about the python-win32 mailing list