Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Python Ïß³Ìͬ²½

¶à¸öÖ´ÐÐÏ߳̾­³£Òª¹²ÏíÊý¾Ý£¬Èç¹û½ö½ö¶ÁÈ¡¹²ÏíÊý¾Ý»¹ºÃ£¬µ«ÊÇÈç¹û¶à¸öÏß³ÌÒªÐ޸Ĺ²ÏíÊý¾ÝµÄ»°¾Í¿ÉÄܳöÏÖÎÞ·¨Ô¤ÁϵĽá¹û¡£
    ¼ÙÈçÁ½¸öÏ̶߳ÔÏót1
ºÍt2
¶¼Òª¶ÔÊýÖµnum=0
½øÐÐÔö1ÔËË㣬ÄÇôt1
ºÍt2
¶¼¸÷¶Ônum
ÐÞ¸Ä10
´ÎµÄ»°£¬ÄÇônum
×îÖյĽá¹ûÓ¦¸ÃΪ20
¡£µ«ÊÇÈç¹ûµ±t1
È¡µÃnum
µÄֵʱ£¨¼ÙÈç´Ëʱnum
Ϊ0
£©£¬ÏµÍ³°Ñt1
µ÷¶ÈΪ“sleeping
”״̬£¬¶ø´Ëʱt2
ת»»Îª“running
”״̬£¬´Ëʱt2
»ñµÃµÄnum
µÄֵҲΪ0
£¬È»ºóËû°Ñnum+1
µÄÖµ1
¸³¸ønum
¡£ÏµÍ³ÓÖ°Ñt2
ת»¯Îª“sleeping
”״̬£¬t1
Ϊ“running
”״̬£¬ÓÉÓÚt1
ÒѾ­µÃµ½num
ֵΪ0
£¬ËùÒÔËûÒ²°Ñnum+1
µÄÖµ¸³¸øÁËnum
Ϊ1
¡£±¾À´ÊÇ2
´ÎÔö1
ÔËÐУ¬½á¹ûÈ´ÊÇnum
Ö»ÔöÁË1
´Î¡£ÀàËÆÕâÑùµÄÇé¿öÔÚ¶àÏß³ÌͬʱִÐеÄʱºòÊÇÓпÉÄÜ·¢ÉúµÄ¡£ËùÒÔΪÁË·ÀÖ¹ÕâÀàÇé¿öµÄ³öÏÖ¾ÍҪʹÓÃÏß³Ìͬ²½»úÖÆ¡£
    ×î¼òµ¥µÄͬ²½»úÖƾÍÊÇ“Ëø”
    Ëø¶ÔÏóÓÃthreading.RLock
Àà´´½¨
    mylock = threading.RLock()
    ÈçºÎʹÓÃËøÀ´Í¬²½Ïß³ÌÄØ£¿Ï߳̿ÉÒÔʹÓÃËøµÄacquire()
£¨»ñµÃ£©·½·¨£¬ÕâÑùËø¾Í½øÈë“locked
”״̬¡£Ã¿´ÎÖ»ÓÐÒ»¸öÏ߳̿ÉÒÔ»ñµÃËø¡£Èç¹ûµ±ÁíÒ»¸öÏß³ÌÊÔͼ»ñµÃÕâ¸öËøµÄʱºò£¬¾Í»á±»ÏµÍ³±äΪ“blocked
”״̬£¬Ö±µ½ÄǸöÓµÓÐËøµÄÏ̵߳÷ÓÃËøµÄrelease()
£¨ÊÍ·Å£©·½·¨£¬ÕâÑùËø¾Í»á½øÈë“unlocked
”״̬¡£“blocked
”״̬µÄÏ߳̾ͻáÊÕµ½Ò»¸ö֪ͨ£¬²¢ÓÐȨÀû»ñµÃËø¡£Èç¹û¶à¸öÏ̴߳¦ÓÚ“blocked
”״̬£¬ËùÓÐÏ̶߳¼»áÏȽâ³ý“blocked
”״̬£¬È»ºóϵͳѡÔñÒ»¸öÏß³ÌÀ´»ñµÃËø£¬ÆäËûµÄÏ̼߳ÌÐø³ÁĬ£¨“blocked
”£©¡£
import threading
mylock = threading.RLock()
class mythread(threading.Thread)
    ...
    def run(self ...):
        ...     #´Ë´¦ ²»¿ÉÒÔ
·ÅÖÃÐ޸Ĺ²ÏíÊý¾ÝµÄ´úÂë
        mylock.acquire()
        ...     #´Ë´¦ ¿ÉÒÔ
·ÅÖÃÐ޸Ĺ²ÏíÊý¾ÝµÄ´úÂë
        mylock.release()
   


Ïà¹ØÎĵµ£º

python Eric µÄʹÓÃ

        ×î½üʹÓÃpython¹ý³ÌÖУ¬python½çÃæµÄ±à³Ì¹¤¾ßGTK-Python£¬µ«ÊǽçÃæµÄÃÀ¹ÛÐÔ²»ÈçQt-CreatorÖеÄQt-Designer£¬ÎÞ·¨ÊµÏÖÉè¼ÆÊÇÊÓͼ»æÖÆ£¬ÓеãÈÃÈËʧÍû¡£
        ÍøÉÏ·¢ÏÖÓÐÈ˽éÉÜpython Eric IDE,±È½ÏºÃÆ棬°²×°ÉÏ¿´¿´°É£º
  &nb ......

pythonµÄC¡¢c++À©Õ¹

pythonµÄC¡¢c++À©Õ¹
http://blog.chinaunix.net/u3/110228/showart_2148725.html
pythonµÄÇ¿´ó²»½ö±íÏÖÔÚÆ书ÄÜÉÏ£¬¶øÇÒ»¹±íÏÖÔÚÆäÀ©Õ¹ÄÜÁ¦ÉÏ¡£
ʹÓÃC/C++ºÜÈÝÒ×±àдpythonµÄÄ£¿é£¬À©Õ¹pythonµÄ¹¦ÄÜ¡£
ͬʱ½«ÐÔÄÜÒªÇó±È½Ï¸ßµÄ´úÂëʹÓÃC/C++±àд£¬ÄܸüºÃµÄÃÖ²¹
½Å±¾ÓïÑÔÖ´ÐÐËÙ¶ÈÂýµÄȱÏÝ¡£
1. pythonµÄCÓïÑÔÀ©Õ¹
1.1 ......

Python intÀàÐͲåÈëÊý¾Ý¿â MySQLdb

 def test2():
 32     db = util.DBUnit('mysql_ab')                                    &nb ......

python µÄtimeÄ£°å·­Ò뼰˵Ã÷

python µÄÄÚǶtimeÄ£°å·­Ò뼰˵Ã÷
Ò»¡¢¼ò½é
timeÄ£¿éÌṩ¸÷ÖÖ²Ù×÷ʱ¼äµÄº¯Êý
˵Ã÷£ºÒ»°ãÓÐÁ½ÖÖ±íʾʱ¼äµÄ·½Ê½:
µÚÒ»ÖÖÊÇʱ¼ä´ÁµÄ·½Ê½(Ïà¶ÔÓÚ1970.1.1 00:00:00ÒÔÃë¼ÆËãµÄÆ«ÒÆÁ¿),ʱ¼ä´ÁÊÇΩһµÄ
µÚ¶þÖÖÒÔÊý×éµÄÐÎʽ±íʾ¼´(struct_time),¹²ÓоŸöÔªËØ£¬·Ö±ð±íʾ£¬Í¬Ò»¸öʱ¼ä´ÁµÄstruct_time»áÒòΪʱÇø²»Í¬¶ø²»Í¬
year ......

ÔÚWindowsÏÂʹÓÃPython±à³Ì

Ò»¡¢Ê¹ÓÃPythonÐèÒªÖªµÀµÄ
ÔÚ Windows ÉÏ£¬°²×° Python ÓÐÁ½ÖÖÑ¡Ôñ¡£
1¡¢ActiveState ÖÆ×÷µÄ ActivePython ÊÇרÃÅÕë¶Ô Windows µÄ Python Ì×¼þ£¬Ëü°üº¬ÁËÒ»¸öÍêÕûµÄ Python ·¢²¼¡¢Ò»¸öÊÊÓÃÓÚPython ±à³ÌµÄ IDE ÒÔ¼°Ò»Ð© PythonµÄ Windows À©Õ¹£¬ÌṩÁËÈ«²¿µÄ·ÃÎÊ Windows APIs µÄ·þÎñ£¬ÒÔ¼° Windows×¢²á±íµÄ×¢²áÐÅÏ¢¡£ËäÈ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ