Hi MF team .. Started using the tool and curious a...
# ask-metaflow
g
Hi MF team .. Started using the tool and curious about how it accepts input from the terminal. For example: I have
Copy code
code = input("Enter verification code: ")
When I dont have metaflow class, I can see the text on the terminal and enter the text. But when I am using the MF class, it hangs, does not show the text and when I enter the code anyways and press Enter, it continues to hang. I have to abort it eventually. Any workarounds?
1
d
The usual way of accepting input is using parameters (see: https://docs.metaflow.org/api/flowspec#parameters). Metaflow tries to keep the “execute locally” and “execute remotely” experience very similar and easily accepting input like that would kind of break it. The internal way metaflow works even for local execution also makes this a little challenging so your best bet in terms of accepting user input is something like that. What is your specific use case, depending on that, there may be something that is more appropriate than this somewhat generic way of doing things.
g
I see .. thanks for the quick reply. Param (per docs) will not work for me as this assumes I will input some value (there is no default value that works) all the time, which is not necessarily the case. There are workarounds I can think of to source the input value, but that is 2x more work for me.
d
why would the parameters not work? You don’t have to specify a default value (if you don’t, metaflow will error out if no value is provided)
(I am not 100% sure how the scheduler integrations work for all OSS cases: argo, sfn, airflow but for all other cases, including those launched on a cluster, it definitely does not reuqire a default).
or maybe I am missunderstanding what it is you are asking.
g
yeah .. sorry. I am skipping the context. I am going to start a new workaround:
Copy code
if __name__ == '__main__':
    s = Session()
    if s.need_new_session:
        get_new_session()
        logger.debug("Got new session")
    else:
        logger.debug("Using old session")
Session is a FlowSpec class. However I notice that no command runs after
s = Session()
. Basically the
if
statement does not get executed.
d
yes, that is expected in a way. the FlowSpec() behaves like a Click UI. You can use
use_cli=False
as an argument but we don’t have great support for non CL invocation so depends on what you want to do. I am also not sure where
need_new_session
is coming from? I am still flying a little blind but it may be better to basically do something more like this:
Copy code
if __name__ == '__main__':
    if need_new_session():
        session = get_new_session()
    else:
        session = get_existing_session()
    subprocess.check_output(["python", "my_flow.py", "run" "--session", json.dumps(session)])
or something to that nature. In other words, do all the pre-metaflow execution stuff first, compute what you need and then use parameters to pass it to Metaflow.
👍 1
(and apologies if that is totally off-base, not entirely sure what you are trying to do)