MPh-py / MPh

Pythonic scripting interface for Comsol Multiphysics
https://mph.readthedocs.io
MIT License
281 stars 71 forks source link

Unicode errors with German COMSOL #24

Closed max3-2 closed 3 years ago

max3-2 commented 3 years ago

When starting the server process on Windows with a German COMSOL installation, this will error out, server.py L92 :

process = start(server + arguments, stdin=PIPE, stdout=PIPE)

        # Wait for it to report the port number.
        t0 = now()
        while process.poll() is None:
            peek = process.stdout.peek().decode()
            if peek.startswith('Username:'):
                error = 'User name and password for Comsol server not set.'
                logger.critical(error)
                logger.info('Start it manually from a system console first:')
                logger.info(' '.join(str(part) for part in server))
                raise RuntimeError(error)
            line = process.stdout.readline().decode()

...since COMSOL prints the word abhören to STDOUT.

An easy fix would be adding ´...decode(errors='ignore')- this would drop the Umlauts but they do not contain any vital information here. Otherwise, switching tolatin_1` also works but seems to be more complicated and prone to errors to me.

john-hen commented 3 years ago

Oh, okay. I didn't think the server messages would be localized. Yes, that would be an easy fix. But doesn't this mean that all the parsing of the server's stdout (for "Username:" and "listening on port xxxx") also doesn't work?

max3-2 commented 3 years ago

I would think so. The localized output with (optional) port redirect is

Port-Nummer 2036 war beschäftigt, benutzt 2037 stattdessen
COMSOL Multiphysics server 5.4 (Build-Version: 388) startete Abhören an Port 2037
Verwende Konsolenbefehl 'close' um Anwendung zu beenden

When using the server initially, it seems to ask for Benutzer, Benutzername or Username fairly inconsistently with version. This all only seems to be the case on windows, which is why I am relating that information and have to go back to a colleague for testing.

john-hen commented 3 years ago

Ugh, that's terrible. But thanks for reporting. I'll try to make the parsing more flexible. Basically we just need to get that four-digit port number. The username check is a nice-to-have. The line ends with a colon though, maybe that's good enough.