设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
查看: 15683|回复: 4
打印 上一主题 下一主题

新人求助 python74课 多线程

[复制链接]

1

主题

0

好友

23

积分

新手上路

Rank: 1

跳转到指定楼层
楼主
发表于 2018-3-20 19:19:18 |只看该作者 |正序浏览
我用的是python3
这是代码
import urllib.request,time,_thread
def get_content(i):
    id=1764796+i
    url = 'https://api.douban.com/v2/movie/subject/%d' % id
    d=urllib.request.urlopen(url).read()
    data.append(d)
    print(i,time.time()-time_start)
    print('data:',len(data))
   
time_start=time.time()
data=[]
for i in range(30):
    print('request movie:',i)
    _thread.start_new_thread(get_content,(i,))
input('press ENTER to exit...\n')







运行结果是这样的:
request movie: 0
request movie: 1
request movie: 2
request movie: 3
request movie: 4
request movie: 5
request movie: 6
request movie: 7
request movie: 8
request movie: 9
request movie: 10
request movie: 11
request movie: 12
request movie: 13
request movie: 14
request movie: 15
request movie: 16
request movie: 17
request movie: 18
request movie: 19
request movie: 20
request movie: 21
request movie: 22
request movie: 23
request movie: 24
request movie: 25
request movie: 26
request movie: 27
request movie: 28
request movie: 29
press ENTER to exit...
Unhandled exception in thread started by Unhandled exception in thread started by Unhandled exception in thread started by Unhandled exception in thread started by Unhandled exception in thread started by Unhandled exception in thread started by Unhandled exception in thread started by Unhandled exception in thread started by Unhandled exception in thread started by Unhandled exception in thread started by 63162021290Unhandled exception in thread started by 8Unhandled exception in thread started by Unhandled exception in thread started by 177Unhandled exception in thread started by 12224Unhandled exception in thread started by Unhandled exception in thread started by 2
>>> <function get_content at 0x062F8810><function get_content at 0x062F8810><function get_content at 0x062F8810><function get_content at 0x062F8810><function get_content at 0x062F8810><function get_content at 0x062F8810><function get_content at 0x062F8810><function get_content at 0x062F8810><function get_content at 0x062F8810><function get_content at 0x062F8810>       <function get_content at 0x062F8810> <function get_content at 0x062F8810><function get_content at 0x062F8810>  <function get_content at 0x062F8810>   <function get_content at 0x062F8810><function get_content at 0x062F8810>




0.90009140968322750.90009140968322750.92193412780761720.92193412780761720.98459267616271970.98459267616271970.9845926761627197
1.0543501377105713
1.05435013771057131.0543501377105713
1.06997585296630861.06997585296630861.1386773586273193
1.3554306030273438Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):



Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):

Traceback (most recent call last):

Traceback (most recent call last):
Traceback (most recent call last):
  File "D:\Program Files(X)\Python\个人文件\lesson74.py", line 6, in get_content
  File "D:\Program Files(X)\Python\个人文件\lesson74.py", line 6, in get_content
  File "D:\Program Files(X)\Python\个人文件\lesson74.py", line 6, in get_content
  File "D:\Program Files(X)\Python\个人文件\lesson74.py", line 6, in get_content
  File "D:\Program Files(X)\Python\个人文件\lesson74.py", line 6, in get_content
  File "D:\Program Files(X)\Python\个人文件\lesson74.py", line 6, in get_content
  File "D:\Program Files(X)\Python\个人文件\lesson74.py", line 6, in get_content
  File "D:\Program Files(X)\Python\个人文件\lesson74.py", line 6, in get_content
  File "D:\Program Files(X)\Python\个人文件\lesson74.py", line 6, in get_content
  File "D:\Program Files(X)\Python\个人文件\lesson74.py", line 6, in get_content
data:data:data:data:data:data:data:  File "D:\Program Files(X)\Python\个人文件\lesson74.py", line 6, in get_content
data:  File "D:\Program Files(X)\Python\个人文件\lesson74.py", line 6, in get_content
  File "D:\Program Files(X)\Python\个人文件\lesson74.py", line 6, in get_content
data:data:  File "D:\Program Files(X)\Python\个人文件\lesson74.py", line 6, in get_content
data:data:data:  File "D:\Program Files(X)\Python\个人文件\lesson74.py", line 6, in get_content
  File "D:\Program Files(X)\Python\个人文件\lesson74.py", line 6, in get_content
data:                                                                              1414141414141414d=urllib.request.urlopen(url).read()d=urllib.request.urlopen(url).read()d=urllib.request.urlopen(url).read()d=urllib.request.urlopen(url).read()d=urllib.request.urlopen(url).read()d=urllib.request.urlopen(url).read()d=urllib.request.urlopen(url).read()d=urllib.request.urlopen(url).read()d=urllib.request.urlopen(url).read()d=urllib.request.urlopen(url).read()d=urllib.request.urlopen(url).read()d=urllib.request.urlopen(url).read()d=urllib.request.urlopen(url).read()1414d=urllib.request.urlopen(url).read()141414d=urllib.request.urlopen(url).read()d=urllib.request.urlopen(url).read()14














  File "D:\Program Files(X)\Python\lib\urllib\request.py", line 223, in urlopen
  File "D:\Program Files(X)\Python\lib\urllib\request.py", line 223, in urlopen
  File "D:\Program Files(X)\Python\lib\urllib\request.py", line 223, in urlopen
  File "D:\Program Files(X)\Python\lib\urllib\request.py", line 223, in urlopen
  File "D:\Program Files(X)\Python\lib\urllib\request.py", line 223, in urlopen
  File "D:\Program Files(X)\Python\lib\urllib\request.py", line 223, in urlopen
  File "D:\Program Files(X)\Python\lib\urllib\request.py", line 223, in urlopen
  File "D:\Program Files(X)\Python\lib\urllib\request.py", line 223, in urlopen
  File "D:\Program Files(X)\Python\lib\urllib\request.py", line 223, in urlopen
  File "D:\Program Files(X)\Python\lib\urllib\request.py", line 223, in urlopen
  File "D:\Program Files(X)\Python\lib\urllib\request.py", line 223, in urlopen
  File "D:\Program Files(X)\Python\lib\urllib\request.py", line 223, in urlopen
  File "D:\Program Files(X)\Python\lib\urllib\request.py", line 223, in urlopen
  File "D:\Program Files(X)\Python\lib\urllib\request.py", line 223, in urlopen
  File "D:\Program Files(X)\Python\lib\urllib\request.py", line 223, in urlopen
  File "D:\Program Files(X)\Python\lib\urllib\request.py", line 223, in urlopen
                    return opener.open(url, data, timeout)            return opener.open(url, data, timeout)            return opener.open(url, data, timeout)return opener.open(url, data, timeout)return opener.open(url, data, timeout)               
return opener.open(url, data, timeout)    return opener.open(url, data, timeout)return opener.open(url, data, timeout)
return opener.open(url, data, timeout)return opener.open(url, data, timeout)return opener.open(url, data, timeout)

回复

使用道具 举报

1

主题

0

好友

23

积分

新手上路

Rank: 1

5#
发表于 2018-3-23 11:24:36 |只看该作者
嗯谢谢了
回复

使用道具 举报

174

主题

45

好友

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

地板
发表于 2018-3-22 22:30:42 |只看该作者
yy123 发表于 2018-3-22 16:49
嗯  报错太多了就没都复制下来
那我的代码应该没问题把
还有个问题就是func(**kargs)   输出的顺序是按照参 ...

py3的字典的确改过
#==== Crossin的编程教室 ====#
微信ID:crossincode
网站:http://crossincode.com
回复

使用道具 举报

1

主题

0

好友

23

积分

新手上路

Rank: 1

板凳
发表于 2018-3-22 16:49:59 |只看该作者
嗯  报错太多了就没都复制下来
那我的代码应该没问题把
还有个问题就是func(**kargs)   输出的顺序是按照参数顺序输出的,并不是无序的,这个是因为python3的关系吗  
谢谢了
回复

使用道具 举报

174

主题

45

好友

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

沙发
发表于 2018-3-21 14:29:16 |只看该作者
请求失败了吧,豆瓣api现在接口频率降低了,它的官方文档里有说

你这个报错不全,没有输出必要的信息
#==== Crossin的编程教室 ====#
微信ID:crossincode
网站:http://crossincode.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-11-23 10:49 , Processed in 0.018106 second(s), 21 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部