Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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ÖÐʱ¼äÓë×Ö·û´®Ö±½ÓµÄת»»

>>> import time
>>> import datetime
>>>
now = time.localtime()
>>> now
(2006, 4, 30, 18, 7, 35,
6, 120, 0)
>>> type(now)
<type 'time.struct_time'>
>>>
str_now = time.strftime("%m/%d/%Y %X", now )
>>>
str_n ......

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

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

Python ÖÐÎÄ×Ö·û´®µÄ½ØÈ¡

def
subString
(s,
length):
   
us = unicode(s, 'utf-8
')
    gs =
us.encode('gb2312
')
    n = int(length)
   
t = gs[:n]
    while True
:
        try
:
  &nb ......

ÓÃpy2exe±àÒëPython³ÌÐò

£¨Ò»£© py2exe¼ò½é
      py2exeÊÇÒ»¸ö½«python½Å±¾×ª»»³ÉwindowsÉϵĿɶÀÁ¢Ö´ÐеĿÉÖ´ÐгÌÐò(*.exe)µÄ¹¤¾ß£¬ÕâÑù£¬Äã¾Í¿ÉÒÔ²»ÓÃ×°python¶øÔÚ
windowsϵͳÉÏÔËÐÐÕâ¸ö¿ÉÖ´ÐгÌÐò¡£
¡¡¡¡
¡¡¡¡py2exeÒѾ­±»ÓÃÓÚ´´½¨
wxPython,Tkinter,Pmw,PyGTK,pygame,win32com
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ºÅ