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

PythonÄÚ²¿µÄÏß³ÌʵÏÖ

ÔÚPythonÖеÄÏß³ÌÔËÐÐʵ¼ÊÊÇÊܵ½InterpreterµÄ¿ØÖÆ»òÕßËµÇ£ÖÆµÄ¡£ÔÚInterpreterµÄºËÐĺ¯Êý
PyObject * PyEval_EvalFrameEx
(PyFrameObject *f, int
throwflag)
ÎÒÃÇ¿ÉÒÔ¿´µ½ÓÐÒ»¸öÈ«¾Ö±äÁ¿_Py_TickerÀ´¿ØÖÆ×ÅÏ̶߳ÔInterpreterµÄÕ¼Óеģ¬Ä¬ÈÏÊÇInterpreterÿִÐÐÒ»°ÙÌõÖ¸Áî¾Í»áÊÍ·ÅÁíÒ»¸öÈ«¾Ö±äÁ¿interpreter_lock.
¶ÔÓÚÿ¸öÐÂỊ̈߳¬ËüÊÇÔõô¼ÓÈëµ½¶ÔInterpreterµÄ¾ºÕùÖÐÀ´µÄÄØ£¿Õâ¸öÎÊÌâÎÒÑо¿ÁËһϡ£ÆäÍ»Èëµã¾ÍÔÚµ±threadÄ£¿éÔÚʹÓÃthread_PyThread_start_new_threadÀ´´´½¨ºÍÆô¶¯ÐÂÏß³Ìʱ£¬ÐÂÏß³ÌµÄÆô¶¯º¯Êý¾ÍÊÇt_bootstrap,ÔÚt_bootstrapÖУ¬Ëû»áʹÓõ½Ò»¸öº¯Êý
void
PyEval_AcquireThread
(PyThreadState *tstate)
´Óµ÷ÓÃÕâ¸öº¯Êý¿ªÊ¼£¬ÐÂÔËÐеÄÏ߳̾ͿªÊ¼Á˽øÈëµ½Õù¶áinterpreterµÄÐÐÁÐÀïÀ´ÁË¡£
¶ÔÓ¦ÓëÕâ¸öº¯Êý»¹ÓÐÒ»¸ö
void
PyEval_ReleaseThread
(PyThreadState *tstate)
ºÜÇå³þ£¬Ò»¸öÊÇÓÃÀ´¶áËøµÄ£¬Ò»¸öÊÇÓÃÀ´·ÅËøµÄ¡£
´ËÍ⣬ÎÒÃÇÖªµÀÈç¹ûÔÚÒ»¸öÏß³ÌÖУ¬¶ÔÓ¦ÓëPythonµÄInterpreterµÄij¸öÖ¸Áîµ÷Ó㬱ÈÈçÊǺ¯Êýµ÷ÓÃÖ¸Á¶øÕâ¸öµ÷Óõĺ¯ÊýÓÐÊÇ»ùÓÚC module extensionÀ´ÊµÏֵ쬶øÔÚÕâ¸öº¯ÊýÖÐÈç¹ûÓÐIO»òÆäËüblockÐ͵IJÙ×÷µÄ»°£¬ÎÞÒÉÕâ¸öÏ̻߳ᱻblock£¬¶øÕâ¸öÏ̱߳»blockÈç¹ûûÓлúÖÆÔÚÈÃÆäËûÏß³ÌÔÚ´ËÏ̱߳»blockʱÇл»Ö´Ðеϰ£¬ÄÇÕâ¸öInterpreterµÄperformance¹À¼Æ¾Í»á¸øÈËÂîËÀÁË£¬ËùÒÔÎÒÃÇ×Ðϸ¿´¿´£¬·¢ÏÖÆäʵÔÚpythonµÄCʵÏÖÊÇÌṩÁËÒ»¸ö»úÖÆÀ´Èñ»blockÏß³ÌÔÚblockÀà²Ù×÷֮ǰÀ´ÈóöInterpreterµÄ¡£
#define
Py_BEGIN_ALLOW_THREADS
#define
 
Py_END_ALLOW_THREADS
ÎÒÏÂÃæcopyÒ»¶ÎcodeÎļþÖеÄÔ­»°£¬À´¿´¿´×÷ÕߵĽâÊÍ£º
/* Interface for threads.
A module that plans to do a blocking system call (or something else
that lasts a long time and doesn't touch Python data) can allow other
threads to run as follows:
...preparations here...
Py_BEGIN_ALLOW_THREADS
...blocking system call here...
Py_END_ALLOW_THREADS
...interpret result here...
The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a
{}-surrounded block.
To leave the block in the middle (e.g., with return), you must insert
a line containing Py_BLOCK_THREADS before the return, e.g.
if (...premature_exit...) {
Py_BLOCK_THREADS
PyErr_Setf


Ïà¹ØÎĵµ£º

»°ËµPython£¨Áù£©Ð¡°×µÄʤÀû

 
    “¹þ¹þ£¡ÖªµÀÎÒ²Ù×÷Ö®ÍõС°×µÄÀ÷º¦Á˰ɣ¡”
    ÿµ±ÖÜÁùÍíÉÏ£¬Ð¡°××ÜÊÇÒª¸úËÞÉáµÄµÜÐÖÌô¼¸¾ÖħÊÞ¡£Æ¾½è×Å·çɧµÄ×ßλºÍâ«ËöµÄÒâʶ£¬Ð¡°××ÜÊÇЦµÀ×îºó¡£Õâ²»£¬Ð¡°×ÓÖÒ»´ÎÈ¡µÃÁËÒÔÒ»µÐ¶þµÄʤÀû¡£
   “Ö÷ÒªÊǶàÏß²Ù×÷£¡”ÕâÊÇС°×¶Ô×Ô¼ºÊ¤ÀûµÄ×ܽ ......

pythonÖеÄlistÈçºÎ½øÐÐÏà¼õ²Ù×÷»òÕß½«list·ÖƬ


ÎÊÌâÃèÊö£º¼ÙÉèÎÒÓÐÕâÑùÁ½¸ölist£¬
          Ò»¸öÊÇlist1£¬list1 = [1, 2, 3, 4, 5]
          Ò»¸öÊÇlist2£¬list2 = [1, 4, 5]
          ÎÒÃÇÈçºÎµÃµ½Ò»¸öеÄlist£ ......

[Ô­´´]Python´úÂëÄ£¿éÈȸüлúÖÆÊµÏÖ(reload)

[Ô­´´]Python´úÂëÄ£¿éÈȸüлúÖÆÊµÏÖ(reload)
by AKara 2009-05-17 @ http://blog.csdn.net/akara @ akaras@163.com
---------------------------------------------------------------------
 
  ¶ÔÒ»¸öÓÎÏ·À´Ëµ£¬ÎÞÂÛÊÇclient»òserver¶¼·Ç³£ÐèÒªÒ»Ì×´úÂëÈȸüеĻúÖÆ¡£
ËüÄÜ´ó´óÌá¸ß¿ª·¢Ð§ÂÊ£¬ÓÖÄܳ¬ºõÍæ ......

pythonÁ´½Ómysql³£¼ûÎÊÌâ

PythonÓëMysql
Ò»¡¢°²×°MySQLdbÄ£¿é
ʹÓÃpythonÁ¬½ÓMysqlµÄǰÌᣬ¾ÍÊÇÐèÒªÒ»¸öÈÃpythonÁ¬½Óµ½MysqlµÄ½Ó¿Ú£¬Õâ¾ÍÊÇMySQLdbÄ£¿é¡£
ÑéÖ¤ÊÇ·ñÒѾ­°²×°ÁËMySQLdb£º
==========================================================
d:\usr\local\Python25>python
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ