一、用shell同時啓動多個python腳本_服務器
1、背景是
有三個腳本a.py, b.py, c.py
三個都是爬蟲,裏面都是while(true)方式運行的,不會主動運行結束。
每次啓動他們,就需要:
python a.py > logs/a.log
python b.py > logs/b.log
python c.py > logs/c.log
2、上linux批處理:
有點麻煩,想搞個批處理:
#!/bin/sh
python a.py > logs/a.log
python b.py > logs/b.log
python c.py > logs/c.log
3、發現有問題
運行發現只有一個python進程,看日誌發現只有a運行了,b和c都沒跑起來。
估計因爲shell是順序執行的,a沒執行完,所以不會去執行b和c,查了一下果然。
4、同時運行方案
不過shell也提供了一個同時運行多個命令的方式:&符號。
於是修改爲:
#!/bin/sh
python a.py > logs/a.log & python b.py > logs/b.log & python c.py > logs/c.log
就可以同時運行三個腳本了。
5、再加工一下
再加工一下,啓動前先停止所有py進程:
#!/bin/sh
ps -ef | grep python | cut -c 9-15| xargs kill -s 9
python a.py > logs/a.log & python b.py > logs/b.log & python c.py > logs/c.log
保存爲restart.sh
可執行權限:chmod +x restart.sh
二、安裝goldenDict及配置
安裝命令:sudo apt install goldendict
本地源詞典配置
1.本地源詞典需要下載,下載網址:http://download.huzheng.org/zh_CN/
進去以後選擇下載詞典,比如說《牛津英漢雙解美化版》
2.在GoldenDict軟件中添加本地源
方法:Edit -> Dictionaries -> Sources -> Files,點擊Add,選擇剛纔創建的本地源目錄,勾選Recursive複選框,點擊OK,完成本地源詞典配置
網絡資源配置:
網絡源詞典配置
網絡源詞典來自網絡。GoldenDict軟件通過添加網絡源詞典網址的方法獲取網絡源詞典。
常見的網絡源網址有:必應、有道、百度。
網址如下
必應:https://cn.bing.com/dict/search?q=%GDWORD%
有道:https://dict.youdao.com/search?q=%GDWORD%&ue=utf8
百度:https://fanyi.baidu.com/#en/zh/%25GDWORD%25
谷歌:https://www.google.com/dictionary?aq=f&langpair=en|en&q=%GDWORD%&hl=en
推薦必應網絡源詞典,界面好看且解釋較全面。下面以配置必應網絡源詞典爲例,介紹網絡源詞典配置的方法。
方法:Edit -> Dictionaries -> Sources -> Websites,點擊Add,在新添的網址輸入框輸入相關信息,勾選Enabled複選框,點擊OK,完成網絡源詞典配置。