Sound alarm when code finishes

前端 未结 11 829
离开以前
离开以前 2021-01-29 17:42

I am in a situation where my code takes extremely long to run and I don\'t want to be staring at it all the time but want to know when it is done.

How can I make the (Py

11条回答
  •  旧时难觅i
    2021-01-29 18:21

    This one seems to work on both Windows and Linux* (from this question):

    def beep():
        print("\a")
    
    beep()
    

    In Windows, can put at the end:

    import winsound
    winsound.Beep(500, 1000)
    
    where 500 is the frequency in Herz
          1000 is the duration in miliseconds
    

    To work on Linux, you may need to do the following (from QO's comment):

    • in a terminal, type 'cd /etc/modprobe.d' then 'gksudo gedit blacklist.conf'
    • comment the line that says 'blacklist pcspkr', then reboot
    • check also that the terminal preferences has the 'Terminal Bell' checked.

提交回复
热议问题