[Python] How can I do asynchronous programming but hide it in Python?

Discussão em 'Python' iniciado por Stack, Julho 12, 2025.

  1. Stack

    Stack Membro Participativo

    Am just getting my head round Twisted, threading, stackless, etc. etc. and would appreciate some high level advice.

    Suppose I have remote clients 1 and 2, connected via a websocket running in a page on their browsers. Here is the ideal goal:

    for cl in (1,2):
    guess[cl] = show(cl, choice("Pick a number:", range(1,11)))
    checkpoint()
    if guess[1] == guess[2]:
    show((1,2), display("You picked the same number!"))


    Ignoring the mechanics of show, choice and display, the point is that I want the show call to be asynchronous. Each client gets shown the choice. The code waits at checkpoint() for all the threads (or whatever) to rejoin.

    I would be interested in hearing answers even if they involve hairy things like rewriting the source code. I'd also be interested in less hairy answers which involve compromising a bit on the syntax.

    Continue reading...

Compartilhe esta Página