Python Ïß³Ìͬ²½¶ÓÁÐ
ÎÒÃǾ³£»á²ÉÓÃÉú²úÕß/Ïû·ÑÕß¹ØÏµµÄÁ½¸öÏß³ÌÀ´´¦ÀíÒ»¸ö¹²Ïí»º³åÇøµÄÊý¾Ý¡£ÀýÈçÒ»¸öÉú²úÕßÏ߳̽ÓÊÜÓû§Êý¾Ý·ÅÈëÒ»¸ö¹²Ïí»º³åÇøÀµÈ´ýÒ»¸öÏû·ÑÕßÏß
³Ì¶ÔÊý¾ÝÈ¡³ö´¦Àí¡£µ«ÊÇÈç¹û»º³åÇøµÄ̫С¶øÉú²úÕߺÍÏû·ÑÕßÁ½¸öÒì²½Ï̵߳ÄËٶȲ»Í¬Ê±£¬ÈÝÒ׳öÏÖÒ»¸öÏ̵߳ȴýÁíÒ»¸öÇé¿ö¡£ÎªÁ˾¡¿ÉÄܵÄËõ¶Ì¹²Ïí×ÊÔ´²¢ÒÔÏàͬ
Ëٶȹ¤×÷µÄ¸÷Ï̵߳ĵȴýʱ¼ä£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒ»¸ö“¶ÓÁДÀ´Ìṩ¶îÍâµÄ»º³åÇø¡£
´´½¨Ò»¸ö“¶ÓÁД¶ÔÏó
import Queue
myqueue = Queue.Queue(maxsize = 10)
Queue.Queue
À༴ÊÇÒ»¸ö¶ÓÁеÄͬ²½ÊµÏÖ¡£¶ÓÁг¤¶È¿ÉΪÎÞÏÞ»òÕßÓÐÏÞ¡£¿Éͨ¹ýQueue
µÄ¹¹Ô캯ÊýµÄ¿ÉÑ¡²ÎÊýmaxsize
À´É趨¶ÓÁг¤¶È¡£Èç¹ûmaxsize
СÓÚ1
¾Í±íʾ¶ÓÁ㤶ÈÎÞÏÞ¡£
½«Ò»¸öÖµ·ÅÈë¶ÓÁÐÖÐ
myqueue.put(10)
µ÷ÓöÓÁжÔÏóµÄput()
·½·¨ÔÚ¶Óβ²åÈëÒ»¸öÏîÄ¿¡£put()
ÓÐÁ½¸ö²ÎÊý£¬µÚÒ»¸öitem
Ϊ±ØÐèµÄ£¬Îª²åÈëÏîÄ¿µÄÖµ£»µÚ¶þ¸öblock
Ϊ¿ÉÑ¡²ÎÊý£¬Ä¬ÈÏΪ1
¡£Èç¹û¶ÓÁе±Ç°Îª¿ÕÇÒblock
Ϊ1
£¬put()
·½·¨¾Íʹµ÷ÓÃÏß³ÌÔÝÍ£,Ö±µ½¿Õ³öÒ»¸öÊý¾Ýµ¥Ôª¡£Èç¹ûblock
Ϊ0
£¬put
·½·¨½«Òý·¢Full
Òì³£¡£
½«Ò»¸öÖµ´Ó¶ÓÁÐÖÐÈ¡³ö
myqueue.get()
µ÷ÓöÓÁжÔÏóµÄget()
·½·¨´Ó¶Óͷɾ³ý²¢·µ»ØÒ»¸öÏîÄ¿¡£¿ÉÑ¡²ÎÊýΪblock
£¬Ä¬ÈÏΪ1
¡£Èç¹û¶ÓÁÐΪ¿ÕÇÒblock
Ϊ1
£¬get()
¾Íʹµ÷ÓÃÏß³ÌÔÝÍ££¬Ö±ÖÁÓÐÏîÄ¿¿ÉÓá£Èç¹ûblock
Ϊ0£¬¶ÓÁн«Òý·¢Empty
Òì³£¡£
ÎÒÃÇÓÃÒ»¸öÀý×ÓÀ´Õ¹Ê¾ÈçºÎʹÓÃQueue
# queue_example.py
from Queue import Queue
import threading
import random
import time
# Producer thread
class Producer(threading.Thread):
def __init__(self, threadname, queue):
threading.Thread.__init__(self, name = threadname)
self.sharedata = queue
def run(self):
for i in range(20):
print self.getName(),'adding',i,'to queue'
self.sharedata.put(i)
time.sleep(random.randrange(10)/10.0)
print self.getName(),'Finished'
# Consumer thread
class Consumer(threading.Thread):
def __init__(self, threadname, queue):
threading.Thread.__init__(self, name = threadname)
self.sharedata = queue
def run(self):
for i in range(20):
print self.getName(),'got a value:',self.sharedata.get()
time.sleep(random.randrange(10)/10.0)
print self.getName(),'Finished'
# Main thread
def main():
queue = Queue(
Ïà¹ØÎĵµ£º
ÏÂÃæÁгöPythonÕýÔò±í´ïʽµÄ¼¸ÖÖÆ¥ÅäÓ÷¨£º
1.²âÊÔÕýÔò±í´ïʽÊÇ·ñÆ¥Åä×Ö·û´®µÄÈ«²¿»ò²¿·Ö
regex=ur"" #ÕýÔò±í´ïʽ
if re.search(regex, subject):
do_something()
else:
do_anotherthing()
2.²âÊÔÕýÔò±í´ïʽÊÇ·ñÆ¥ÅäÕû¸ö×Ö·û´®
regex=ur"\Z" #ÕýÔò±í´ïʽĩβÒÔ\ ......
ÓÃpythonдµÄץȡÌìÆøÔ¤±¨µÄ½Å±¾
http://blog.chinaunix.net/u2/82009/showart_2166843.html
´Ó×òÌ쿪ʼµÄ¿´¹ØÓÚÍøÂçץȡµÄ¶«Î÷£¬¶øÇÒ×Ô¼ºµÄÓõÄÊÇawesome £¬ËùÒÔдÁËÕâ¸öÌìÆøÔ¤±¨µÄ½Å±¾¸øÎÒµÄawesome£¬Õâ¸öÌìÆø½Å±¾Ö±½ÓÈ¡ÏÂÀ´µÄ»°ÊÇÆßÌìµÄÌìÆøÔ¤±¨´ÓÖйúÌìÆøÍøÉÏ£¬ÎÒºóÃæ¶ÔËü×öÁË´¦Àí£¬Óõ½ÁËÎÒµÄawesomeÉÏ
Ч¹û£º1ÈÕÐÇ ......
Ò»¡¢Ê¹ÓÃPythonÐèÒªÖªµÀµÄ
ÔÚ Windows ÉÏ£¬°²×° Python ÓÐÁ½ÖÖÑ¡Ôñ¡£
1¡¢ActiveState ÖÆ×÷µÄ ActivePython ÊÇרÃÅÕë¶Ô Windows µÄ Python Ì×¼þ£¬Ëü°üº¬ÁËÒ»¸öÍêÕûµÄ Python ·¢²¼¡¢Ò»¸öÊÊÓÃÓÚPython ±à³ÌµÄ IDE ÒÔ¼°Ò»Ð© PythonµÄ Windows À©Õ¹£¬ÌṩÁËÈ«²¿µÄ·ÃÎÊ Windows APIs µÄ·þÎñ£¬ÒÔ¼° Windows×¢²á±íµÄ×¢²áÐÅÏ¢¡£ËäÈ ......
PythonµÄÄÚ´æÐ¹Â©¼°gcÄ£¿éµÄʹÓÃ
-- 6.11ÈÕ´íÎóÐÞÕý°æ
Horin|ºØÇÚ
Email: horin153@msn.com
......
¶à¸öÖ´ÐÐÏ߳̾³£Òª¹²ÏíÊý¾Ý£¬Èç¹û½ö½ö¶ÁÈ¡¹²ÏíÊý¾Ý»¹ºÃ£¬µ«ÊÇÈç¹û¶à¸öÏß³ÌÒªÐ޸Ĺ²ÏíÊý¾ÝµÄ»°¾Í¿ÉÄܳöÏÖÎÞ·¨Ô¤ÁϵĽá¹û¡£
¼ÙÈçÁ½¸öÏ̶߳ÔÏót1
ºÍt2
¶¼Òª¶ÔÊýÖµnum=0
½øÐÐÔö1ÔËË㣬ÄÇôt1
ºÍt2
¶¼¸÷¶Ônum
ÐÞ¸Ä10
´ÎµÄ»°£¬ÄÇônum
×îÖյĽá¹ûÓ¦¸ÃΪ20
¡£µ«ÊÇÈç¹ûµ±t1
È¡µÃnum
µÄֵʱ£¨¼ÙÈç´Ë ......