←back to thread

320 points willm | 1 comments | | HN request time: 0.197s | source
Show context
dapperdrake ◴[] No.45106399[source]
Python's async is very difficult to use and debug. It seems to get stuck randomly, read like race conditions. And Python cannot work around this nicely with their lambdas only permitting a single expression in their body.

Not worth the trouble. Shell pipelines are way easier to use. Or simply waiting —no pun intended— for the synchronous to finish.

replies(1): >>45106678 #
mixmastamyk ◴[] No.45106678[source]
> lambdas only permitting a single expression

Use a tuple, maybe walrus, and return the last item[-1].

replies(1): >>45109314 #
dapperdrake ◴[] No.45109314[source]
That idea sounds good.

How do I get variables for not redoing long-running computations that depend on one-another? So, what if the third tuple value depends on the second and the second in turn depends on the first?

replies(2): >>45109470 #>>45110665 #
1. mixmastamyk ◴[] No.45110665[source]
That’s what walrus is for:

    future = lambda age: (
        print('Your age is:', age),
        older := age + 5,
        print('Your age in the future:', older),
        older,
    )[-1]

    print(future(20))

    # out
    Your age is: 20
    Your age in the future: 25
    25