z0x010 / pytool

Automatically exported from code.google.com/p/pytool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

接收线程的问题

GoogleCodeExporter opened this issue · comments

正常登录,使用手机号。
应该维登录成功,而且没有错误。但是虽然登录成功,但接��
�线程内有错误发生。
Exception in thread Thread-2:                                                
Traceback (most recent call last):                                           
  File "/usr/lib/python2.6/threading.py", line 522, in __bootstrap_inner     
    self.run()                                                               
  File "./fetion.py", line 30, in run                                        
    for e in self.phone.receive():                                           
  File "/home/dong/下载/PyFetion/PyFetion.py", line 1218, in receive         
    if type == "ServiceResult":                                              
UnboundLocalError: local variable 'type' referenced before assignment 

我用的是Version:0.2 OS:Fedora11 Python:2.6

我看了一下,可能是刚开始的第一条response只包含 
<events></events>,用
re.findall('<event type="(.+?)"',response)之后,返回空列表的问题。
我将
type = re.findall('<event type="(.+?)"',response)[0]
这一句改成
type = re.findall('<event type="(.+?)"',response)
type = type[0]
之后,就正常了。不知道是不是Python自己的问题。

Original issue reported on code.google.com by donglong...@gmail.com on 21 Apr 2010 at 8:37

===================================================
恩,刚刚checkout了最新的版本,这儿没有问题了。
请无视这个issue吧。

Original comment by donglong...@gmail.com on 22 Apr 2010 at 2:04

好象还是有问题。
可能是多线程的原因,错误有时候发生有时候正常。
应该是第一次返回空列表后使用[0],发生IndexError异常造成的�
��
在这个异常处理的最后,加上continue就好了。
只不过,在异常处理中改变程序流程,可能不太好哦。。。

Original comment by donglong...@gmail.com on 22 Apr 2010 at 3:05

Original comment by cocobear.cn on 25 Nov 2010 at 8:54

  • Changed state: Invalid