Do not call SetErrorMode on windows since this is now done at startup by calibre-launcher.dll

This commit is contained in:
Kovid Goyal 2017-06-30 10:11:51 +05:30
parent b47b9ab123
commit 0e1f81b4b0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -19,22 +19,18 @@ if iswindows:
drive_ok_lock = Lock() drive_ok_lock = Lock()
def drive_is_ok(letter, max_tries=10, debug=False): def drive_is_ok(letter, max_tries=10, debug=False):
import win32api, win32file import win32file
with drive_ok_lock: with drive_ok_lock:
oldError = win32api.SetErrorMode(1) # SEM_FAILCRITICALERRORS = 1 for i in xrange(max_tries):
try: try:
for i in xrange(max_tries): win32file.GetDiskFreeSpaceEx(letter+':\\')
try: return True
win32file.GetDiskFreeSpaceEx(letter+':\\') except Exception as e:
return True if i >= max_tries - 1 and debug:
except Exception as e: prints('Unable to get free space for drive:', letter)
if i >= max_tries - 1 and debug: prints(as_unicode(e))
prints('Unable to get free space for drive:', letter) time.sleep(0.2)
prints(as_unicode(e)) return False
time.sleep(0.2)
return False
finally:
win32api.SetErrorMode(oldError)
_USBDevice = namedtuple('USBDevice', _USBDevice = namedtuple('USBDevice',
'vendor_id product_id bcd manufacturer product serial') 'vendor_id product_id bcd manufacturer product serial')
@ -300,5 +296,6 @@ def main(args=sys.argv):
test_for_mem_leak() test_for_mem_leak()
return 0 return 0
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())