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

Python Ï̳߳Ø


import Queue, threading, sys
from threading import Thread
import time,urllib
# working thread
class Worker(Thread):
   worker_count = 0
   def __init__( self, workQueue, resultQueue, timeout = 0, **kwds):
       Thread.__init__( self, **kwds )
       self.id = Worker.worker_count
       Worker.worker_count += 1
       self.setDaemon( True )
       self.workQueue = workQueue
       self.resultQueue = resultQueue
       self.timeout = timeout
       self.start( )
   def run( self ):
       ''' the get-some-work, do-some-work main loop of worker threads '''
       while True:
           try:
               callable, args, kwds = self.workQueue.get(timeout=self.timeout)
               res = callable(*args, **kwds)
               print "worker[%2d]: %s" % (self.id, str(res) )
               self.resultQueue.put( res )
           except Queue.Empty:
               break
           except :
               print 'worker[%2d]' % self.id, sys.exc_info()[:2]
               
class WorkerManager:
   def __init__( self, num_of_workers=10, timeout = 1):
       self.workQueue = Queue.Queue()
       self.resultQueue = Queue.Queue()
       self.workers = []
       self.timeout = timeout
       self._recruitThreads( num


Ïà¹ØÎĵµ£º

Python×°ÊÎÆ÷

Ô­ÎÄ£ºhttp://www.klipdas.com/blog/?p=python-decorator
python×°ÊÎÆ÷½éÉÜ
Python 2.2ÖÐÒýÈëµÄ classmethod() ºÍ staticmethod() ÄÚÖú¯Êý£¬Äã¿ÉÒÔÕâÑùµ÷ÓÃclassmethod()£º
class A:
def foo(self, y):
print y
foo = classmethod(foo)
Ò²¿ÉÒÔÕâÑù£º
class A:
@classmethod
def foo(sel ......

Python and MySQL

 ½üÀ´ÐèÒªÓÃPython¶ÔMySQLÊý¾Ý¿â½øÐвÙ×÷¡£Python¾ÃÎÅÆäÃû£¬Î´¼ûÆä“ÈË”£»Êý¾Ý¿âÔø¾­ºÜ¸ß·Ö£¬ÔçÒÑ»¹¸øÏÈÉú£¬¸üÎÞMySQL¾­Ñé¡£ÓÚÊÇÒ»ÇдÓÁ㿪ʼ£¬½è»úºÃºÃѧϰһ·¬¡£
PythonÕâ¸ö½Å±¾ÓïÑÔȷʵÃû¸±Æäʵ£¬ÓÃÁ˼¸Ìì±ãϲ»¶ÉÏËüÀ²¡£ºÜ¼ò½à£¬ºÜ·½±ã¡£ÒÔËõ¼õ×÷Ϊģ¿é·Ö¸î·û£¬¶ÁÆðÀ´ÉÍÐÄÔÃÄ¿¡£pythonµÄÄÚ½¨Êý¾ÝÀàÐÍ£¨ ......

ÔÚPythonÖж¯Ì¬°ó¶¨property

 ÔÚPythonÖпÉÒÔ°Ñproperty¶¯Ì¬µÄ°ó¶¨µÄobjectµÄ¼Ì³ÐÀàÖУ¬²¢ÇÒ¿ÉÒÔ¶¨Òå´øÓвÎÊýµÄgetºÍset·½·¨¡£
±ÈÈ磬ÎÒÃǶ¨ÒåÁËÈ«¾Ö±äÁ¿g£¬È»ºóͨ¹ýÁ½¸ö·½·¨À´´æÈ¡gµÄÄÚÈÝ
def get_g(self):
    return g
def set_g(self, _g):
    global g
    g = _g
¶¨ÒåÒ»¸öobjectµÄ¼Ì³ ......

python º¯Êý

PythonÖк¯Êý²ÎÊýµÄ´«µÝÊÇͨ¹ý“¸³Öµ”À´´«µÝµÄ¡£µ«ÕâÌõ¹æÔòÖ»»Ø´ðÁ˺¯Êý²ÎÊý´«µÝµÄ“Õ½ÂÔÎÊÌ┣¬²¢Ã»Óлشð“Õ½ÊõÎÊÌ┣¬Ò²¾Í˵ûÓлشðÔõô¸³ÖµµÄÎÊÌâ¡£º¯Êý²ÎÊýµÄʹÓÿÉÒÔ·ÖΪÁ½¸ö·½Ã棬һÊǺ¯Êý²ÎÊýÈçºÎ¶¨Ò壬¶þÊǺ¯ÊýÔÚµ÷ÓÃʱµÄ²ÎÊýÈçºÎ½âÎöµÄ¡£¶øºóÕßÓÖÊÇÓÉÇ°Õß¾ö¶¨µÄ¡£º¯Êý²ÎÊýµÄ¶¨ ......

[¶À¼Ò]Google½«ÏÞÖÆPythonÓïÑÔµÄÓ¦Óà ¿ª·¢ÉçÇøÈÈÒé

2009-11-16 
Collin WinterÊÇPythonÉçÇøһλÆľßÓ°ÏìÁ¦µÄ¿ª·¢Õߣ¬ËûÔøÊÇCPythonÏîÄ¿µÄºËÐÄ¿ª·¢ÕßÖ®Ò»¡¢Ò²ÔøÊÇUnladen Swallow£¨¼ûÎÄĩעÊÍ£©µÄºËÐÄ¿ª·¢Õߣ¬²ÎÓëÁ˺ܶàPythonÏîÄ¿µÄ¿ª·¢¡£½üÀ´´«ÎÅGoogle½«ÔÚÆäÐÂÏîÄ¿ÖÐÏÞÖÆPythonµÄʹÓã¬Îª´ËÓпª·¢Õߣ¨ÒÔK±íʾ£©ÔÚGoogle ÂÛ̳Öй«¿ªÑ¯ÎÊÁËCollin Winter£¬Collin Winte ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ