Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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 Challenge£¨0

Ò»¸öÓÐȤµÄÍøÕ¾£º
http://www.pythonchallenge.com/
¼¯ÓéÀÖÓëѧϰÓÚÒ»Ì壬ÔÚ¿ª¶¯ÄԽ¹ØµÄ¹ý³ÌÖУ¬²»µ«À©Õ¹ÁË˼ά£¬»¹¶ÔPython¼ÓÉîÁËÀí½â¡£
Ò»¹²33¹Ø£¬Ã¿´³¹ýÒ»¹Ø¶¼¿ÉÒÔÔÚÌáʾϲ鿴×÷Õ߸ø³öµÄSolution¡£
µÚ0¹Ø£¨Ö¸µ¼¹Ø£©£º
    ³öÏÖÒ»·ù»­Ã棬ÉÏÃæд×Å2**38£¬½ÌÄãÈçºÎ½øÈëÏÂÒ»¹Ø¡£  
&nb ......

PythonÓÐÓõÄÄ£¿é

http://chardet.feedparser.org/  ×Ô¶¯¼ì²â±àÂë
http://effbot.org/zone/celementtree.htm  cElementTree
http://github.com/jaybaird/python-bloomfilter bloomfilter
http://docs.python.org/library/threading.html#threading.activeCount threading ......

pythonÖеÄroundÄÚ½¨º¯Êý

 ½ñÌìÓÖɨÁËÒ»±éÊý×ÖÕâÒ»ÕÂ.. ¿´µ½ÁËround()º¯Êý, ÊÇÔÚpythonºËÐıà³Ì˼ÏëµÄ5.6.2½ÚµÄĩβ, Ô­ÎÄÈçÏÂ:
round(flt, ndig=0) ½ÓÊÜÒ»¸ö¸¡µãÊý flt ²¢¶ÔÆäËÄÉáÎåÈ룬±£´æ ndigλСÊý¡£
Èô²»Ìṩndig ²ÎÊý£¬ÔòĬÈÏСÊýµãºó0λ¡£
round()½öÓÃÓÚ¸¡µãÊý¡££¨ÒëÕß×¢£ºÕûÊýÒ²¿ÉÒÔ£¬ ²»¹ý²¢Ã»ÓÐʲô
ʵ¼ÊÒâÒ壩
Æäʵ, ×ö¸ö浄 ......

pythonÖеÄexec º¯Êý

      ÔÚÏîÄ¿ÀïÃæÒ»¸ö½âÎöÎı¾µÄ¹¤¾ßÀïÃæÓõ½ÁËÕâ¸öÃüÁîÀ´¸³Öµ£¬¿ªÊ¼Ò»Ö±ÖªµÀÒâ˼£¬ºÇºÇ ²éÁËÏ£¬ÕÒµ½·½·¨ÈçÏ£º
exec
Óï¾äÓÃÀ´Ö´Ðд¢´æÔÚ×Ö·û´®»òÎļþÖеÄPythonÓï¾ä¡£ÀýÈ磬ÎÒÃÇ¿ÉÒÔÔÚÔËÐÐʱÉú³ÉÒ»¸ö°üº¬Python´úÂëµÄ×Ö·û´®£¬È»ºóʹÓÃ
exec
Óï¾äÖ´ÐÐÕâЩÓï¾ä¡£ÏÂÃæÊÇÒ»¸ö¼òµ¥µÄÀý×Ó¡£
> ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ