Close pre-existing figures in matplotlib when running from eclipse

后端 未结 4 971
悲&欢浪女
悲&欢浪女 2021-02-04 23:27

My question is simple: I have a python script that generates figures using matplotlib. Every time i run it it generates new windows with figures. How can I have the script close

4条回答
  •  不思量自难忘°
    2021-02-04 23:48

    It will kill not only all plot windows, but all processes that are called python3, except the current script you run. It works for python3. So, if you are running any other python3 script it will be terminated. As I only run one script at once, it does the job for me.

    import os
    import subprocess
    subprocess.call(["bash","-c",'pyIDs=($(pgrep python3));for x in "${pyIDs[@]}"; do if [ "$x" -ne '+str(os.getpid())+' ];then  kill -9 "$x"; fi done'])
    

提交回复
热议问题