Python Stop current Python REPL command, but keep REPL session open?

  • Thread starter Thread starter Swamp Thing
  • Start date Start date
  • Tags Tags
    Python
Click For Summary
When a command in the Python REPL is stuck in a synchronous wait, such as when using websocket.recv() that is waiting for a message, the recommended method to terminate just that command is to use Control-C. This keyboard interrupt allows users to exit the blocking command and return to the REPL prompt without losing the entire session. This technique is commonly effective for handling situations where a command is unresponsive.
Swamp Thing
Insights Author
Messages
1,041
Reaction score
775
If you just typed in a command into the Python repl, and it is stuck in a synchronous "waiting-for-something-to-happen", how can we terminate just that command and return to the same repl session?

For example, say we typed websocket.recv() and the websocket is waiting for a message... how can we end that and get back to the repl prompt without losing the whole session?
 
Technology news on Phys.org
Try control-c it usually works as a keyboard interrupt.
 
  • Like
Likes PeterDonis and Swamp Thing
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 16 ·
Replies
16
Views
5K
Replies
55
Views
6K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 22 ·
Replies
22
Views
6K
  • · Replies 3 ·
Replies
3
Views
3K