Hi, community I am studying how workflow works and...
# flyte-support
d
Hi, community I am studying how workflow works and found that
Copy code
@workflow
def my_wf() -> str:
    print("@@@ i am in")
    res = say_hello()
    return res
if I execute it locally,
Copy code
@@@ i am in
@@@ i am in
Will appear in my terminal Can anyone explain why or guide me some reference ? Thanks a lot !
l
Hey @damp-lion-88352, I'm guessing your task
say_hello
also has the same print statement in it?
d
No it doesn’t But thanks a lot for your help !
r
Same here, you can assume say_hello return a string “hello” It will print the @@ I am in twice
l
Would you care to show the code for
say_hello
?
r
sure, following is the code.
Copy code
def say_hello():
    return "hello"

@workflow
def my_wf() -> str:
    print("@@@ i am in")
    res = say_hello()
    return res

my_wf()
l
Ahh okay, and you're executing with
pyflyte run
?
r
just run it locally.
a
In my understanding: 1. first print: happened because flytekit compiles the workflow to DAG 2. second print: happened at run time.
l
Yeah I don't think you need to call it explicitly at the bottom of the script. If you remove
my_wf()
it should work as expected
a
If you also print the
res
, the first print will be promise, the second print will be flytekit literal.
👀 1
r
I see, looks like the compile will also trigger the print function. if I change the code to the following, it will print 5 line, 4 from my_wf, 1 from last line. Does this result meet yours expectation? @acceptable-window-92672 @loud-belgium-4006
Copy code
@workflow
def my_wf() -> str:
    print("@@@ i am in")
    res = say_hello()
    print(type(res))
    return res

print(my_wf())
a
Yes. Do you see that the first type (res) printed is a promise, while the second is actually a literal?
r
Not really, that’s an another topic, it simply print.
Copy code
@@@ i am in
<class 'str'>
@@@ i am in
<class 'str'>
hello
a
Can you try print(res)?
r
Copy code
@@@ i am in
hello
@@@ i am in
hello
hello
Not sure if it’s related to the env I run
l
Hmm interesting, I was expecting one of the print(type(res)) to be a promise. I guess it depends how you're executing, if it's just with
python
or
pyflyte run
. But otherwise expected.. if you remove the
()
from
print(my_wf())
you should only get one print loop.
r
my bad
Copy code
@task
def say_hello()->str:
    return "hello"
we should @ task
so that it can be wrapped as a promise
Copy code
@@@ i am in
Promise(node:n0.o0)
@@@ i am in
Resolved(o0=<FlyteLiteral scalar { primitive { string_value: "hello" } }>)
hello
Does these are the expected result? @acceptable-window-92672 @loud-belgium-4006
a
YES!!!
l
Yeah that makes more sense
r
when we compile, we should get a promise, however, if we get the 2nd at run time => we should get the literal, right?
l
Yes - the literal value will be produced at run time instead of the promise
r
Thanks for your explaination! @loud-belgium-4006 @acceptable-window-92672 Thanks!
👍 1
l
Also checkout the
pyflyte run
vs
python
section here that describes the different ways of running locally, if you haven't seen it yet.. https://docs.flyte.org/projects/cookbook/en/latest/index.html
r
Thanks for the help!
l
No worries!
g
you should not use print in the workflow. @workflow is used to define your DAG. when you run the workflow on flyte cluster, flyte will only run each individual task (say_hello) in the pod, and won’t run workflow function (my_wf). if you want to use print, for loop in the workflow, you can use @dynamic.
d
Thanks a lot for @loud-belgium-4006 @acceptable-window-92672 @refined-doctor-1380 @glamorous-carpet-83516 your guys help ! I will absorb those knowledge !
👍 1