Any application that writes data to the standard out or standard error stream, or that takes data from the standard in stream, interacts with the terminal it is executing on.
Although that may sound complicated, it simply means that if your script uses print() or input(), how it behaves exactly from the point of view of the user will depend on the terminal the user is running it in. The terminal has to do the actual displaying of what is printed and it does the actual job of collecting user input. (Note that this gets more complicated if you use libraries that directly interact with system APIs reading keyboard input, like keyboard)
This terminal can be the Windows Console Host (the default for Command Prompt in early Windows 10 and before), the Windows Terminal (the default for PowerShell in Windows 11), but also a terminal emulator running your script on the cloud over SSH (running in some terminal emulation mode) for example, or whatever terminal your Linux distribution implements.
When you execute your script from an IDE, it can implement its own terminal that may work slightly differently from the terminal you're used to on your operating system. PyCharm is a good example. Its terminal behaves differently from both the Windows Terminal and the Windows Console Host, even though you may be running it on Windows.
A script that uses both terminal input and output and multiprocessing can cause additional confusion, if you're relying on the terminal responding in some timely fashion. Your script runs as expected on Windows Console Host and Windows Terminal, but doesn't on PyCharm's terminal.
In PyCharm, you can easily see this difference by running your script directly from the IDE with some run configuration. And then running it again from the 'Terminal' prompt with something like python myscript.py. You'll find that the behaviour in a system terminal is fine.
(Unrelated note: your input prompt says to press "any key", but input() will only terminate your script if someone presses Enter/Return, since that completes the collection of input by input())
You can't really 'fix' this, since there's nothing to fix - everything is working as it should. However, if the input() statement is only there for debugging purposes, a solution would be to use a library (like keyboard) that waits for user input without relying on the running Terminal. Install it with pip install keyboard or using the Project Settings in the UI, and then try this:
from multiprocessing import Process
import time
from keyboard import read_key
def proc(text):
while True:
print(text)
time.sleep(1)
if __name__ == '__main__':
p = Process(target=proc, args=('hi',))
p.start()
print("Press any key to stop the process...")
read_key()
p.terminate()
Note that this actually stops when you press any key, and works the same in all terminals.
__main__and__mp_main__being printed??multiprocessing.Process. This is why I ask. Even when I use PyCharm, atlhough I'm mostly on VSCode nowadays, I still just run the code from the terminal in PyCharm manually.input('Press any key to exit')call inside the try/except as you suggested but the program didn't throw any exceptions. Also, I checked, and theinputfunction is not returning righ away. It seems to be a problem in PyCharm's execution script or something like that. Even in online Python interpreters this code is working like expected.