msl.loadlib.server32 module
Contains the base class for loading a 32-bit shared library in 32-bit Python.
The Server32
class is used in combination with the
Client64
class to communicate with a 32-bit shared library
from 64-bit Python.
- class msl.loadlib.server32.Server32(path, libtype, host, port, *args, **kwargs)[source]
Bases:
HTTPServer
Base class for loading a 32-bit library in 32-bit Python.
All modules that are to be run on the 32-bit server must contain a class that is inherited from this class and the module can import any of the standard python modules except for
distutils
,ensurepip
,tkinter
andturtle
.All modules that are run on the 32-bit server must be able to run on the Python interpreter that the server is running on, see
version()
for how to determine the version of the Python interpreter.- Parameters:
path (
str
) – The path to the 32-bit library. SeeLoadLibrary
for more details.libtype (
str
) –The library type. See
LoadLibrary
for more details.host (
str
) – The IP address of the server.port (
int
) – The port to run the server on.*args – All additional arguments are currently ignored.
**kwargs – All keyword arguments are passed to
LoadLibrary
.
- property assembly
Returns a reference to the .NET Runtime Assembly object if the shared library is a .NET Framework otherwise returns
None
.Tip
The JetBrains dotPeek program can be used to reliably decompile any .NET Assembly into the equivalent source code.
- property lib
Returns the reference to the 32-bit, loaded-library object.
For example, if libtype is
- static version()[source]
Gets the version of the Python interpreter that the 32-bit server is running on.
- Returns:
str
– The result of executing'Python ' + sys.version
on the 32-bit server.
Examples
>>> from msl.loadlib import Server32 >>> Server32.version() 'Python 3.11.4 ...'
Note
This method takes about 1 second to finish because the 32-bit server needs to start in order to determine the version of the Python interpreter.
- static interactive_console()[source]
Start an interactive console.
This method starts an interactive console, in a new terminal, with the Python interpreter on the 32-bit server.
Examples
>>> from msl.loadlib import Server32 >>> Server32.interactive_console()
- property quiet
This attribute is no longer used, it will be removed in a future release.
Returns
True
.
- static remove_site_packages_64bit()[source]
Remove the site-packages directory from the 64-bit process.
By default, the site-packages directory of the 64-bit process is included in
sys.path
of the 32-bit process. Having the 64-bit site-packages directory available can sometimes cause issues. For example, comtypes imports numpy so if numpy is installed in the 64-bit process then comtypes will import the 64-bit version of numpy in the 32-bit process. Depending on the version of Python and/or numpy this can cause the 32-bit server to crash.New in version 0.9.
Examples
import sys from msl.loadlib import Server32 class FileSystem(Server32): def __init__(self, host, port, **kwargs): # remove the site-packages directory that was passed from 64-bit Python # before calling the super() function to load the COM library path = Server32.remove_site_packages_64bit() super(FileSystem, self).__init__('Scripting.FileSystemObject', 'com', host, port) # optional: add the site-packages directory back into sys.path sys.path.append(path)
- static is_interpreter()[source]
Check if code is running on the 32-bit server.
If the same module is executed by both
Client64
andServer32
then there may be only parts of the code that should be executed by the correct bitness of the Python interpreter.New in version 0.9.
- Returns:
bool
– Whether the code is running on the 32-bit server.
Examples
import sys from msl.loadlib import Server32 if Server32.is_interpreter(): # this only gets executed on the 32-bit server assert sys.maxsize < 2**32