Skip to content

Commit de9070e

Browse files
committed
win32: explain what's going on when importing the win32* modules
Mick reports that importing the win32* modules may fail because they import win32api which is a pyd file. We catched this by trying to import win32api even though we were not actually making use of it but then code analysers complain about unusued import. This commit makes it so that we import what we actually use and documents why we are manipulating PATH (which was previously not clear anyway).
1 parent 9b58109 commit de9070e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

microscope/win32.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
import os
55
import sys
66

7+
# These win32* modules both import win32api which is a pyd file.
8+
# Importing win32api can be problematic because of Windows things
9+
# specially when running as a Windows. So if it fails, add the
10+
# executable path to the DLL search PATH.
711
try:
8-
import win32api
12+
import win32serviceutil
13+
import win32service
914
except:
10-
# Add executable path to DLL search PATH.
1115
os.environ['PATH'] += ';' + os.path.split(sys.executable)[0]
12-
import win32api
16+
import win32serviceutil
17+
import win32service
1318

1419
import multiprocessing
1520
import servicemanager
16-
import win32serviceutil
17-
import win32service
1821

1922
class MicroscopeWindowsService(win32serviceutil.ServiceFramework):
2023
""" Serves microscope devices via a Windows service.

0 commit comments

Comments
 (0)