Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: signal.pause() equivalent on Windows

I have my main application thread that spawns 2 threads and I catch SIGINT in my main thread to quit them nicely. On linux, I'm using signal.pause() and it works perfectly.

What is the best way to implement signal.pause() on Windows?

My ugly solution is:

my_queue.get(True, averylongtime)

And put something in my_queue in my signal handler. Note that if I don't specify a timeout, SIGINT is not caught. But I wonder if there's a better solution.

Thank you

like image 665
RaphDG Avatar asked Mar 01 '26 08:03

RaphDG


1 Answers

Although it is not beautiful you can do something like this

import os, platform

match platform.system():
    case 'Linux':
        signal.pause()   
    case 'Windows':
         os.system('pause')
    case _:
        <default case>
like image 198
Dakolas Avatar answered Mar 03 '26 21:03

Dakolas