免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 7522 | 回复: 3
打印 上一主题 下一主题

求助:pydev的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-05-30 15:13 |只看该作者 |倒序浏览
刚学python,用pydev写一个测试多线程的小程序,代码如下:
  1. import thread

  2. def run(n):
  3.     print n

  4. def test():
  5.     thread.start_new_thread(run,(1,))
  6.     thread.start_new_thread(run,(2,))

  7. if __name__=='__main__':
  8.     test()
复制代码
在IDLE下运行正常,用pydev直接运行,提示如下错误:
Unhandled exception in thread started by
sys.excepthook is missing
lost sys.stderr
Unhandled exception in thread started by
sys.excepthook is missing
lost sys.stderr

求教解决方法

论坛徽章:
0
2 [报告]
发表于 2011-05-30 20:13 |只看该作者
回复 1# 0xC1988
  1. if __name__=='__main__':
  2.     test()   
  3.     time.sleep(10)
复制代码
thread模块已经不推荐使用了,考虑使用threading模块。

论坛徽章:
0
3 [报告]
发表于 2011-05-30 22:43 |只看该作者
谢谢楼上的

论坛徽章:
2
2015年迎新春徽章
日期:2015-03-04 09:55:28IT运维版块每日发帖之星
日期:2016-07-29 06:20:00
4 [报告]
发表于 2011-05-31 09:59 |只看该作者
回复 1# 0xC1988
可参考一下http://blog.chinaunix.net/space. ... o=blog&id=96074
    threads = {}
    for i in dict_cmd:
        t=threading.Thread(target=write_notes,args=(dict_cmd,log_02,i))
        threads=t
    for i in dict_cmd:
        threads.start()
        time.sleep(2)
    for i in dict_cmd:
        threads.join()
    db_curs.close()
    db_conn.close()
#创建一个Thread 的实例,传给它一个函数target,参数args
#threading是多线程
#三个循环,将线程都存在threads{}字典中;依次开始;程序挂起,直到线程结束。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP