Python Ï̲߳Ù×÷
ÔÚpythonÖÐÈçºÎ´´½¨Ò»¸öÏ̶߳ÔÏó
Èç¹ûÄãÒª´´½¨Ò»¸öÏ̶߳ÔÏ󣬺ܼòµ¥£¬Ö»ÒªÄãµÄÀà¼Ì³Ðthreading.Thread£¬È»ºóÔÚ__init__ÀïÊ×Ïȵ÷ÓÃthreading.ThreadµÄ__init__·½·¨¼´¿É
import threading
class mythread(threading.Thread):
def __init__(self, threadname):
threading.Thread.__init__(self, name = threadname)
....
Õâ²Å½ö½öÊǸö¿ÕỊ̈߳¬Îҿɲ»ÊÇÒªËûÀ¿Õ³µµÄ£¬Ëû¿ÉµÃ¸øÎҸɵãʵÔڻºÜ¼òµ¥£¬ÖØдÀàµÄrun()·½·¨¼´¿É£¬°ÑÄãÒªÔÚÏß³ÌÖ´ÐÐʱ×öµÄÊÂÇ鶼·Åµ½ÀïÃæ
import threading
import time
class mythread(threading.Thread):
def __init__(...):
....
def run(self):
for i in range(10):
print self.getName, i
time.sleep(1)
ÒÔÉÏ´úÂëÎÒÃÇÈÃÕâ¸öÏß³ÌÔÚÖ´ÐÐÖ®ºóÿ¸ô1ÃëÊä³öÒ»´ÎÐÅÏ¢µ½ÆÁÄ»£¬10´Îºó½áÊø
getName()ÊÇthreading.ThreadÀàµÄÒ»¸ö·½·¨£¬ÓÃÀ´»ñµÃÕâ¸öÏ̶߳ÔÏóµÄname¡£»¹ÓÐÒ»¸ö·½·¨setName()µ±È»¾ÍÊÇÀ´ÉèÖÃÕâ¸öÏ̶߳ÔÏóµÄnameµÄÁË¡£
Èç¹ûÒª´´½¨Ò»¸öỊ̈߳¬Ê×ÏȾÍÒªÏÈ´´½¨Ò»¸öÏ̶߳ÔÏó
mythread1 = mythread('mythread 1')
Ò»¸öÏ̶߳ÔÏó±»´´½¨ºó£¬Ëû¾Í´¦ÓÚ“born”£¨µ®Éú״̬£©
ÈçºÎÈÃÕâ¸öÏ̶߳ÔÏó¿ªÊ¼ÔËÐÐÄØ?Ö»Òªµ÷ÓÃÏ̶߳ÔÏóµÄstart()·½·¨¼´¿É
mythread1.start()
ÏÖÔÚÏ߳̾ʹ¦ÓÚ“ready”״̬»òÕßÒ²³ÆΪ“runnable”״̬¡£
Ææ¹ÖÂ𣿲»ÊÇÒѾstartÁËÂð£¿ÎªÊ²Ã´²»³ÆΪ“running”״̬ÄØ£¿ÆäʵÊÇÓÐÔÒòµÄ¡£ÒòΪÎÒÃǵļÆËã»úÒ»°ãÊDz»¾ßÓÐÕæÕý²¢Ðд¦ÀíÄÜÁ¦µÄ¡£ÎÒÃÇËùνµÄ¶àÏß³ÌÖ»ÊÇ°Ñʱ¼ä·Ö³ÉƬ¶Î£¬È»ºó¸ôÒ»¸öʱ¼ä¶Î¾ÍÈÃÒ»¸öÏß³ÌÖ´ÐÐһϣ¬È»ºó½øÈë“sleeping ”״̬£¬È»ºó»½ÐÑÁíÒ»¸öÔÚ“sleeping”µÄỊ̈߳¬Èç´ËÑ»·runnable->sleeping->runnable... £¬Ö»ÊÇÒòΪ¼ÆËã»úÖ´ÐÐËٶȺܿ죬¶øʱ¼äƬ¶Î¼ä¸ôºÜС£¬ÎÒÃǸÐÊܲ»µ½£¬ÒÔΪÊÇͬʱ½øÐеġ£ËùÒÔ˵һ¸öÏß³ÌÔÚstartÁËÖ®ºóÖ»ÊÇ´¦ÔÚÁË¿ÉÒÔÔËÐеÄ״̬£¬ËûʲôʱºòÔËÐл¹ÊÇÓÉϵͳÀ´½øÐе÷¶ÈµÄ¡£
ÄÇÒ»¸öÏß³Ìʲôʱºò»á“dead”ÄØ£¿Ò»°ãÀ´Ëµµ±Ï̶߳ÔÏóµÄrun·½·¨Ö´ÐнáÊø»òÕßÔÚÖ´ÐÐÖÐÅ׳öÒì³£µÄ»°£¬ÄÇôÕâ¸öÏ߳̾ͻá½áÊøÁË¡£ÏµÍ³»á
Ïà¹ØÎĵµ£º
¼Æ»®Õâ¸öÐÇÆÚѧϰÓÃpythonʵÏÖ¾ö²ßÊ÷Ëã·¨¡£½ñÍí¾ÍÅöµ½Á˺öàÎÊÌ⣬ºÃ¾ÃûÓÐÓÃpythonÁË£¬²¢ÇÒ3.0ºÍÊé±¾ÉϵÄÓÐЩ¶«Î÷²»Ì«Ò»Ö£¬ÕâÀï¼Ç¼Ï¼¸¸öµØ·½¡£
1£© import module Èç¹û²»ÊÇÔÚ±ê׼Ŀ¼Ï£¨ÏµÍ³µÄpath£¬pythonµÄĿ¼£¬µ±Ç°Ä¿Â¼£©£¬ÄÇôÐèÒªÏÈimport sys£¬È»ºósys.path.append('')£»
2£© ¸Ä±äÔ´Îļþºó£¬ÔÙ´Îimport ......
2005-2006ѧÄêµÚ1ѧÆÚ
±à Òë Ô Àí
¿Î ³Ì Éè ¼Æ ±¨ ¸æ
°à¼¶ 02¼Æ(¶þ)
ѧºÅ 19
ÐÕÃû ÁõÏþÃ÷
³É¼¨
Ö¸µ¼½Ìʦ ¬³¯»Ô
Ò»¡¢ Éè¼ÆÄ¿µÄ
¼ÓÉî¶Ô±àÒ ......
PythonǶÈëC++Ïê½â(1)--HelloWorld
À´CSDNµÄʱºò£¬¸Õ¸Õ½Ó´¥Python£¬ÄÇʱºò¶ÔPythonµÄǶÈ벿·ÖºÜ¸ÐÐËȤ£¬Ö»ÊÇһֱûÓÐʱ¼äÀ´ÅªÇåÆäÃæÉ´£¬Òò´ËҲһֱûÓÐʹÓÃǶÈëµÄ¹¦ÄÜ£¬ÁíÒ»¸öÔÒòÊÇÎÒ»¹Ã»ÓÐÕæÕýÓÃPythonд¹ýÒ»¸öÕýʽµÄÓÐÓõãµÄ¶«Î÷£¬²»¹ý£¬ÏÖÔڻعýÍ·À´¼ÌÐø¿´ÕâÒ»²¿·Ö£¬·¢ÏÖ»¹ÊÇͦ¼òµ¥µÄ¡£ÒÔÇ°Ïë°ÑÕⲿ·Ö·Òë³öÀ´£¬¿ÉÊÇÓ ......
½üÀ´ÐèÒªÓÃPython¶ÔMySQLÊý¾Ý¿â½øÐвÙ×÷¡£Python¾ÃÎÅÆäÃû£¬Î´¼ûÆä“ÈË”£»Êý¾Ý¿âÔø¾ºÜ¸ß·Ö£¬ÔçÒÑ»¹¸øÏÈÉú£¬¸üÎÞMySQL¾Ñé¡£ÓÚÊÇÒ»ÇдÓÁ㿪ʼ£¬½è»úºÃºÃѧϰһ·¬¡£
PythonÕâ¸ö½Å±¾ÓïÑÔȷʵÃû¸±Æäʵ£¬ÓÃÁ˼¸Ìì±ãϲ»¶ÉÏËüÀ²¡£ºÜ¼ò½à£¬ºÜ·½±ã¡£ÒÔËõ¼õ×÷Ϊģ¿é·Ö¸î·û£¬¶ÁÆðÀ´ÉÍÐÄÔÃÄ¿¡£pythonµÄÄÚ½¨Êý¾ÝÀàÐÍ£¨ ......
You are here: Home ‣ Dive Into Python 3 ‣
Difficulty level: ♦♢♢♢♢
Installing Python °²×°Python
❝ Tempora mutantur nos et mutamur in illis. (Times change, and we change with them.) ❞
— ancient Roman proverb
D ......