V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
m_z
V2EX  ›  Python

python程序一个小问题求解

  •  
  •   m_z · 2012-07-10 23:28:59 +08:00 · 4394 次点击
    这是一个创建于 4279 天前的主题,其中的信息可能已经有所发展或是发生改变。
    很抱歉,这里要贴代码了:


    执行结果:
    [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前面有个空格阿?不改代码的情况下会出现第一种结果
    15 条回复    1970-01-01 08:00:00 +08:00
    m_z
        1
    m_z  
    OP
       2012-07-10 23:29:40 +08:00
    唉,这里直接把空格都给干掉了阿。。
    eric_q
        2
    eric_q  
       2012-07-10 23:59:14 +08:00
    Please use gist.
    m_z
        3
    m_z  
    OP
       2012-07-11 08:52:43 +08:00
    @eric_q 请教一下,gist怎么用?
    yujnln
        4
    yujnln  
       2012-07-11 09:08:40 +08:00
    试试看这样贴
    <script src="https://gist.github.com/3087266.js"> </script>
    @m_z
    yujnln
        5
    yujnln  
       2012-07-11 09:10:25 +08:00
    darcy
        6
    darcy  
       2012-07-11 09:12:38 +08:00   ❤️ 1
    @yujnln @m_z
    使用HTTP的链接,URL单独放一行,或者URL前后留一个空格,然后就会自动转换成gist里的代码了
    http://gist.github.com/3087266
    yujnln
        7
    yujnln  
       2012-07-11 09:14:46 +08:00
    @darcy 谢谢,原来不支持https
    m_z
        8
    m_z  
    OP
       2012-07-11 09:31:51 +08:00
    汗。。刷新了才看到,害我贴了这么多次。
    @darcy url单独放一行我大概明白了,url是不是还不包括.js?
    GordianZ
        9
    GordianZ  
    MOD
       2012-07-11 09:45:31 +08:00
    @m_z url 直接贴地址栏 url, 没有任何扩展名。
    m_z
        10
    m_z  
    OP
       2012-07-11 09:52:14 +08:00
    m_z
        11
    m_z  
    OP
       2012-07-11 09:53:39 +08:00
    ok,谢谢大家,gist我终于会了,可是问题谁给解释解释?
    ayanamist
        12
    ayanamist  
       2012-07-11 12:18:30 +08:00   ❤️ 1
    如果你是问空格问题的话,因为print走的是stdout,是block设备,存在线程安全问题,所以那个空格其实就是没加锁是的数据混乱。你在print前后用Lock锁住应该就没事了。
    其实打log最好用logging,是线程安全的。
    m_z
        13
    m_z  
    OP
       2012-07-11 13:00:17 +08:00
    @ayanamist 是这个问题,谢谢指导阿。
    Fikhtengol
        14
    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
        15
    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>
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2805 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 12:55 · PVG 20:55 · LAX 05:55 · JFK 08:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.