From 0e1f81b4b067d291fa5b6142c3df1b95ab3da9fa Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 30 Jun 2017 10:11:51 +0530 Subject: [PATCH] Do not call SetErrorMode on windows since this is now done at startup by calibre-launcher.dll --- src/calibre/devices/scanner.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/calibre/devices/scanner.py b/src/calibre/devices/scanner.py index ee726aec13..327093d392 100644 --- a/src/calibre/devices/scanner.py +++ b/src/calibre/devices/scanner.py @@ -19,22 +19,18 @@ if iswindows: drive_ok_lock = Lock() def drive_is_ok(letter, max_tries=10, debug=False): - import win32api, win32file + import win32file with drive_ok_lock: - oldError = win32api.SetErrorMode(1) # SEM_FAILCRITICALERRORS = 1 - try: - for i in xrange(max_tries): - try: - win32file.GetDiskFreeSpaceEx(letter+':\\') - return True - except Exception as e: - if i >= max_tries - 1 and debug: - prints('Unable to get free space for drive:', letter) - prints(as_unicode(e)) - time.sleep(0.2) - return False - finally: - win32api.SetErrorMode(oldError) + for i in xrange(max_tries): + try: + win32file.GetDiskFreeSpaceEx(letter+':\\') + return True + except Exception as e: + if i >= max_tries - 1 and debug: + prints('Unable to get free space for drive:', letter) + prints(as_unicode(e)) + time.sleep(0.2) + return False _USBDevice = namedtuple('USBDevice', 'vendor_id product_id bcd manufacturer product serial') @@ -300,5 +296,6 @@ def main(args=sys.argv): test_for_mem_leak() return 0 + if __name__ == '__main__': sys.exit(main())