python队列queue不堵塞_Python多进程不能将信息放入队列

1.Python多进程不能将信息放入队列

2.代码:

from urllib import request

from bs4 import BeautifulSoup

from multiprocessing import Manager

from multiprocessing import Pool

import os

def hand_url(url,name,queue):

room_message = {} #存放我需要的信息

print(name,os.getpid())

one_roomlist=[]

req=request.Request(url)

req.add_header('User-Agent','Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36')

with request.urlopen(req)as f:

data = f.read().decode()

soup = BeautifulSoup(data, 'html.parser')

clear_1 = soup.find_all(class_="table_type_7 responsive_table full_width t_align_l")

clear_1 = clear_1[0].tbody.contents

for i in clear_1:

if i != '\n':

message_small = []

for x in i.strings:

if x != '\n':

message_small.append(x)

one_roomlist.append(message_small)

room_message[name] = one_roomlist

#前半部分为爬去网页信息和筛选内容

print(room_message)

queue.put(room_message) #程序在这里卡住了,room_message为一个字典

print('ok')

if __name__ == '__main__':

queue=Manager().Queue()

pool = Pool(4)

pool.apply_async(hand_url,('http://202.115.129.139:81/trainingroomnote?roomid=91','A405',queue))

pool.close()

pool.join()

print(queue.get())

3.问题截图

4.我自己尝试把print(room_message)得到的内容直接复制添加到队列里面是可以的,但是一旦改成queue.put(room_message)程序是卡在这里的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值