2

How do you execute a function, while the program is still taking input from the user, because all the code after

user_input = input()

is not run until the user inputs something.

So how do I run a function while the user is typing an input?

Thank you!

Edit: People were asking why I need to do this, so I am making an online TextRPG game, where people can chat as well, but what I want is while you are typing, chat should update. Also I have not tried any code yet, because I don't get how to do it.

  • 1
    By running it on another thread. Why do you need to run a function while waiting for input? – Jared Smith Jan 05 '21 at 02:10
  • share your code so we can see what you have tried. What are your desired output? – Joe Ferndz Jan 05 '21 at 02:13
  • @JoeFerndz I have edited my post to answer your questions. – juicyguyzer Jan 05 '21 at 02:41
  • @JaredSmith I have edited my post to answer your questions. – juicyguyzer Jan 05 '21 at 02:41
  • It is not a simple answer. Why don't you research a bit and also look at some of the example posts in stackoverflow to get an idea of what you are trying to do. For ex: see this thread https://stackoverflow.com/questions/36060346/creating-a-simple-chat-application-in-python-sockets – Joe Ferndz Jan 05 '21 at 02:45
  • 3
    Have you researched what is required to create an online game written in python? It is much more complex than you probably imagine. – RufusVS Jan 05 '21 at 02:47
  • 2
    Does this answer your question? [Python async: Waiting for stdin input while doing other stuff](https://stackoverflow.com/questions/58454190/python-async-waiting-for-stdin-input-while-doing-other-stuff) – SiAce Jan 05 '21 at 02:49
  • Use `celery` https://docs.celeryproject.org. See also https://docs.celeryproject.org/en/stable/getting-started/introduction.html and https://riptutorial.com/celery/example/23628/celery-plus-redis – aerijman Jan 05 '21 at 03:00

2 Answers2

-2

You can use the concept of multi threading.

Shashank KR
  • 83
  • 1
  • 9
-2
test_number = int(input("Enter a number: "))