我正在研究python2.7项目。我设置了一个包含10个进程的进程池。我的代码结构是:
pool = Pool(10)
pool.map(ProcessJson, jsonFiles)
def ProcessJson(jsonpath):
# doing something and get (int)numUrls
for idx in xrange(numUrls):
flag = DownloadVideo(paras).run()
if flag == 0:
continue
class DownloadVideo():
def __init__(para):
# init
def run(self):
try:
videopath = os.path.join(folder, sname.encode("utf-8"))
try:
cmd = "wget -q -c --limit-rate=1M --tries=3 -T10 -P %s --output-document=%s \"%s\"" % (folder, videopath, url)
ret = os.system(cmd)
if (ret >> 8) != 0:
logger.error("cmd error---" + str(ret >> 8) + "---" + cmd + "\n")
return 0
except Exception as e:
logger.error("python system cmd error---", e)
return 0
except Exception as e1:
logger.error("exception with downloading---", e1)
return 0
一段时间后,该过程全部进入睡眠状态。我使用sudo strace -p pid
和lsof -p pid
来查找问题。我得到的显示:
sudo strace -p 27723
Process 27723 attached
wait4(-1,
然后我找到了它的子进程27724
sudo strace -p 27724
Process 27724 attached
read(6,
cat wchan 27724
do_wait_data
:/proc/27724$ ls -l ./fd
l-wx------ 1 cwz domain^users 64 7月 12
16:20 3 -> Documents/tools/log/__main__-1.log
lr-x------ 1 cwz domain^users 64 7月 12
16:20 4 -> pipe:[8180487]
l-wx------ 1 cwz domain^users 64 7月 12 16:20 5 ->
chenweizhao/Documents/tools/GoogleImages-
1/Tim_Faraday/xXP4smHFrfLw9M.jpg
lrwx------ 1 cwz domain^users 64 7月 12 16:20 6 -> socket:
[8286859]
l-wx------ 1 cwz domain^users 64 7月 12
16:20 7 -> pipe:[8180490]
lr-x------ 1 cwz domain^users 64 7月 12
16:20 8 -> /dev/null
和
lsof -p 27724
wget 27724 cwz 3w REG 8,2 427352 5786641
chenweizhao/tools/log/__main__-1.log
wget 27724 cwz 4r FIFO 0,8 0t0 8180487 pipe
wget 27724 cwz 5w REG 8,2 24404 9971506
chenweizhao/tools/GoogleImages-1/Tim_Faraday/xXP4smHFrfLw9M.jpg
wget 27724 cwz 6u IPv4 8286859 0t0
TCP myIP:47496->ec2-13-56-87-172.us-west-1.compute.amazonaws.com:https
(ESTABLISHED)
wget 27724 cwz 7w FIFO 0,8 0t0
8180490 pipe
wget 27724 cwz 8r CHR 1,3 0t0 1029
/dev/null
我该如何解决问题?非常感谢你!