1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Python run code while process is running?

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

  1. Stack

    Stack Membro Participativo

    Python inject/evaluate/run python code while process is already running, for example, infinite loop

    counter = 0
    while True:
    counter += 1
    print(f"baz: {counter}")
    time.sleep(1)


    I would like to attach/spawn python interpreter (preferably interactive python interpreter) and for example change value of counter

    I think this would be very cool & useful for game development where i can write new code and edit values while the game is running.

    i was able to do this:

    import time
    import code
    import threading

    counter = 0

    def start_repl():
    code.interact(local=globals())

    threading.Thread(target=start_repl, daemon=True).start()

    while True:
    counter += 1
    print(f"baz: {counter}")
    time.sleep(1)


    but its not that interactive and python prompt and input is in the same terminal as code baz: x output so it makes it cumbersome to use.

    by interactive i mean, tab symbol completion in terminal.

    Continue reading...

Compartilhe esta Página