msl.loadlib.client64 module

Contains the base class for communicating with a 32-bit library from 64-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.client64.Client64(module32, *, add_dll_directory=None, append_environ_path=None, append_sys_path=None, host='127.0.0.1', port=None, protocol=5, rpc_timeout=None, server32_dir=None, timeout=10, **kwargs)

Bases: object

Base class for communicating with a 32-bit library from 64-bit Python.

Starts a 32-bit server, Server32, to host a Python class that is a wrapper around a 32-bit library. Client64 runs within a 64-bit Python interpreter, and it sends a request to the server which calls the 32-bit library to execute the request. The server then provides a response back to the client.

Changed in version 0.6: Added the rpc_timeout argument.

Changed in version 0.8: Added the protocol argument and the default quiet value became None.

Changed in version 0.10: Added the server32_dir argument.

Changed in version 1.0: Removed the deprecated quiet argument. The host value may now be None. Added the add_dll_directory argument.

Parameters:
  • module32 (PathLike) – The name of, or the path to, a Python module that will be imported by the 32-bit server. The module must contain a class that inherits from Server32.

  • add_dll_directory (PathLike | Iterable[PathLike] | None) – Add path(s) to the 32-bit server’s DLL search path. See os.add_dll_directory() for more details. Available on Windows only.

  • append_environ_path (PathLike | Iterable[PathLike] | None) – Append path(s) to the 32-bit server’s os.environ['PATH'] variable. This may be useful if the library that is being loaded requires additional libraries that must be available on PATH.

  • append_sys_path (PathLike | Iterable[PathLike] | None) –

    Append path(s) to the 32-bit server’s sys.path variable. The value of sys.path from the 64-bit process is automatically included, i.e.,

    sys.path(32bit) = sys.path(64bit) + append_sys_path.

  • host (str | None) – The hostname (IP address) of the 32-bit server. If None then the connection to the server is mocked. See Mocking the connection to the server for more details.

  • port (int | None) – The port to open on the 32-bit server. If None, an available port will be used.

  • protocol (int) – The pickle protocol to use.

  • rpc_timeout (float | None) – The maximum number of seconds to wait for a response from the 32-bit server. The RPC timeout value is used for all requests from the server. If you want different requests to have different timeout values, you will need to implement custom timeout handling for each method on the server. Default is None, which means to use the default timeout value used by the socket module (which is to wait forever).

  • server32_dir (PathLike | None) – The directory where the frozen 32-bit server is located.

  • timeout (float) – The maximum number of seconds to wait to establish a connection with the 32-bit server.

  • kwargs (Any) – All additional keyword arguments are passed to the Server32 subclass. The data type of each value is not preserved. It will be of type str at the constructor of the Server32 subclass.

Raises:

Note

If module32 is not located in the current working directory then you must either specify the full path to module32 or you can specify the folder where module32 is located by passing a value to the append_sys_path parameter. Using the append_sys_path option also allows for any other modules that module32 may depend on to also be included in sys.path so that those modules can be imported when module32 is imported.

property host: str | None

The host address of the 32-bit server.

property port: int

The port number of the 32-bit server.

property connection: HTTPConnection | None

The connection to the 32-bit server.

property lib32_path: str

The path to the 32-bit shared-library file.

request32(name, *args, **kwargs)

Send a request to the 32-bit server.

Parameters:
  • name (str) – The name of a method, property or attribute of the Server32 subclass.

  • args (Any) – The arguments that the method in the Server32 subclass requires.

  • kwargs (Any) – The keyword arguments that the method in the Server32 subclass requires.

Returns:

Whatever is returned by calling name.

Raises:
  • Server32Error – If there was an error processing the request on the 32-bit server.

  • ResponseTimeoutError – If a timeout occurs while waiting for the response from the 32-bit server.

Return type:

Any

shutdown_server32(kill_timeout=10)

Shutdown the 32-bit server.

This method shuts down the 32-bit server, closes the client connection, and deletes the temporary file that is used to save the serialized pickle’d data.

Changed in version 0.6: Added the kill_timeout argument.

Changed in version 0.8: Returns the (stdout, stderr) streams from the 32-bit server.

Parameters:

kill_timeout (float) – If the 32-bit server is still running after kill_timeout seconds, the server will be killed using brute force. A warning will be issued if the server is killed in this manner.

Returns:

The (stdout, stderr) streams from the 32-bit server. Limit the total number of characters that are written to either stdout or stderr on the 32-bit server to be < 4096. This will avoid potential blocking when reading the stdout and stderr PIPE buffers.

Return type:

tuple[BinaryIO, BinaryIO]

Note

This method gets called automatically when the reference count to the Client64 object reaches zero (see __del__()).