python程序一个小问题求解

2012-07-10 23:28:59 +08:00
 m_z
很抱歉,这里要贴代码了:
http://gist.github.com/3087266

执行结果:
[mz@mz python]$ python queue.py
0: Looking for the next enclosure
1: Looking for the next enclosure
*** Main thread waiting
*** Done

这是正常的,有时候结果是这样的:
[mz@mz python]$ python queue.py
0: Looking for the next enclosure
1: Looking for the next enclosure

第二种情况,为啥1前面有个空格阿?不改代码的情况下会出现第一种结果
4428 次点击
所在节点    Python
15 条回复
m_z
2012-07-10 23:29:40 +08:00
唉,这里直接把空格都给干掉了阿。。
eric_q
2012-07-10 23:59:14 +08:00
Please use gist.
m_z
2012-07-11 08:52:43 +08:00
@eric_q 请教一下,gist怎么用?
yujnln
2012-07-11 09:08:40 +08:00
试试看这样贴
<script src="https://gist.github.com/3087266.js"> </script>
@m_z
yujnln
2012-07-11 09:10:25 +08:00
darcy
2012-07-11 09:12:38 +08:00
@yujnln @m_z
使用HTTP的链接,URL单独放一行,或者URL前后留一个空格,然后就会自动转换成gist里的代码了
http://gist.github.com/3087266
yujnln
2012-07-11 09:14:46 +08:00
@darcy 谢谢,原来不支持https
m_z
2012-07-11 09:31:51 +08:00
汗。。刷新了才看到,害我贴了这么多次。
@darcy url单独放一行我大概明白了,url是不是还不包括.js?
GordianZ
2012-07-11 09:45:31 +08:00
@m_z url 直接贴地址栏 url, 没有任何扩展名。
m_z
2012-07-11 09:52:14 +08:00
m_z
2012-07-11 09:53:39 +08:00
ok,谢谢大家,gist我终于会了,可是问题谁给解释解释?
ayanamist
2012-07-11 12:18:30 +08:00
如果你是问空格问题的话,因为print走的是stdout,是block设备,存在线程安全问题,所以那个空格其实就是没加锁是的数据混乱。你在print前后用Lock锁住应该就没事了。
其实打log最好用logging,是线程安全的。
m_z
2012-07-11 13:00:17 +08:00
@ayanamist 是这个问题,谢谢指导阿。
Fikhtengol
2013-02-12 02:49:40 +08:00
<script src="https://gist.github.com/3087266.js">
def get_sql_res(self,sql):
try:
self.cu.execute(sql)
except Exception,e:
print str(e)
return 0,str(e)
res=self.cu.fetchall()
return res,""

</script>
Fikhtengol
2013-02-12 02:51:06 +08:00
def get_sql_res(self,sql):
try:
self.cu.execute(sql)
except Exception,e:
print str(e)
return 0,str(e)
res=self.cu.fetchall()
return res,""

<script src="https://gist.github.com/3087266.js"> </script>

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/42024

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX