multiscale / muscle3

The third major version of the MUltiScale Coupling Library and Environment
Apache License 2.0
25 stars 13 forks source link

Manager doesn't flush print of its ip:port string #216

Closed peter-t-fox closed 11 months ago

peter-t-fox commented 1 year ago

If starting the manager and models manually from a script, the script needs to capture the tcp:<ip>:<port> string printed by the manager, and pass it to the models in their environment.

However, the manager's stdout is not flushed, and so this is difficult e.g.

$ muscle_manager --no-start-all configuration.ymmsl > stdout.txt &
[1] <pid>
$ cat stdout.txt
$ 

We can force a flush by using the PYTHONUNBUFFERED environment variable:

$ PYTHONUNBUFFERED=1 muscle_manager --no-start-all configuration.ymmsl > stdout.txt &
[2] <pid>
$ cat stdout.txt 
tcp:127.0.0.1:9000

or by using python -u to start the manager.

Since the network information printed to stdout is needed for use in the case where the user is starting each of the components manually, it might be helpful to support that use case by updating the line:

print(manager.get_server_location())

to

print(manager.get_server_location(), flush=True)

This way the user doesn't have to manually force a flush of the buffer.

LourensVeen commented 1 year ago

Hi Peter, sorry for the slow reaction, and thanks for reporting!

I'll probably add a command line option to write the string to a file to avoid potential confusion with other output, but I'll keep this and make sure to flush the buffer as well.

peter-t-fox commented 1 year ago

Great, thank you.

LourensVeen commented 1 year ago

Hi Peter, I've added a new option (#238) that writes the location to a file. If it's not given, the manager will write the location to standard output as before, but now with a flush. Will that work for you?

LourensVeen commented 1 year ago

This was released with version 0.7.0. Could you please test, and if this fixes it for you, close this issue?

peter-t-fox commented 1 year ago

Thanks! Sorry I didn't see this sooner: I don't seem to have notifications enabled. I am still working with version 0.6.0, but I should be able to test this soon. Thanks for making this change: it looks like it should do what I need.

peter-t-fox commented 11 months ago

@LourensVeen I have switched to using MUSCLE3 0.7.0, and I have had an opportunity to test this. It's now working as I would expect: the addition of flush=True means I don't have to to force the manager to print the IP address via PYTHONUNBUFFERED or similar.

So I think this issue can now be closed: thanks for your help!