[python-win32] GetFileVersionInfo blocks main thread
Rickey, Kyle W
Kyle.Rickey at bakerhughes.com
Sat Apr 19 02:10:23 CEST 2008
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
More information about the python-win32
mailing list