摘要:
摘选: TcpV2 15.10节tsleep and wakeup Functions阻塞: When a process executing within the kernel cannot proceed because a kernelresource is unavailable, it waits for the resource by calling tsleep, which hasthe following prototype: int tsleep (caddr_t chan, int pri, char *mesg, int timeo); The first... 阅读全文
摘要:
copy— Shallow and deep copy operations Assignment statements in Python do not copy objects, they create bindings between a target and an object. For collections that are mutable or contain mutable items, a copy is sometimes needed so one can change one copy without changing the other. This module p. 阅读全文
摘要:
记录tornado文档中对自己有用的信息:A Tornado web application maps URLs or URL patterns to subclasses oftornado.web.RequestHandler. Those classes defineget()orpost()methods to handle HTTPGETorPOSTrequests to that URL.The request handler can access the object representing the current request withself.request.TheHTT 阅读全文
摘要:
之前在讨论闭包的时候有提到: Python会按LEGB的顺序来搜索变量:要说明的是,这里的访问规则只对普通变量有效, 对象属性的规则与这无关(简单地说,访问一个对象的属性与此无关)。L. Local. 局部作用域,即函数中定义的变量(没有用global声明)E. Enclosing. 嵌套的父级函数的局部作用域,即包含此函数的上级函数的局部作用域,比如上面的示例中的labmda所访问的x就在其父级函数test的局部作用域里。通常也叫non-local作用域。G. Global(module). 在模块级别定义的全局变量(如果需要在函数内修改它,需要用global声明)B. Built-... 阅读全文
摘要:
区别Being educated under Java background, static method and class method are the same thing.But not so in Python, there is subtle difference:Sayfunction a()is defined inParentClass, whileSubClass extendsParentClassIf functiona()has@staticmethoddecorator,Sub.a()still refers to definition insideParentCl 阅读全文
摘要:
Sincestr.format()is quite new, a lot of Python code still uses the%operator. However, because this old style of formatting will eventually be removed from the language,str.format()should generally be used.More information can be found in theString Formatting Operationssection.老式的("%s id %s" 阅读全文
摘要:
连接5.5 Stopping and Starting Multi-thread Programsgdbsupports debugging programs with multiple threads (seeDebugging Programs with Multiple Threads). There are two modes of controlling execution of your program within the debugger. In the default mode, referred to asall-stop mode, when any thread in 阅读全文
摘要:
AstralWind的博客上有对函数式编程很好地讲解,一下做一些节选1.1. 什么是函数式编程?函数式编程使用一系列的函数解决问题。函数仅接受输入并产生输出,不包含任何能影响产生输出的内部状态。任何情况下,使用相同的参数调用函数始终能产生同样的结果。 在一个函数式的程序中,输入的数据“流过”一系列的函数,每一个函数根据它的输入产生输出。函数式风格避免编写有“边界效应”(side effects)的函数:修改内部状态,或者是其他无法反应在输出上的变化。完全没有边界效应的函数被称为“纯函数式的”(purely functional)。避免边界效应意味着不使用在程序运行时可变的数据结构,输出只依赖. 阅读全文
摘要:
自省 自省。正如你所知道的,Python中万物皆对象,自省是指代码可以查看内存中以对象形式存在的其它模块和函数,获取它们的信息,并对它们进行操作。用这种方法,你可以定义没有名称的函数,不按函数声明的参数顺序调用函数,甚至引用事先并不知道名称的函数。反射 有时候我们会碰到这样的需求,需要执行对象的某个方法,或是需要对对象的某个字段赋值,而方法名或是字段名在编码代码时并不能确定,需要通过参数传递字符串的形式输入。举个具体的例子:当我们需要实现一个通用的DBM框架时,可能需要对数据对象的字段赋值,但我们无法预知用到这个框架的数据对象都有些什么字段,换言之,我们在写框架的时候需要通过某种机制访... 阅读全文
摘要:
... Complex Processes - Threads...Some OSes, including otherUnixes, have the seperate concept of aprocessoptionally consisting of several seperatethreads, orlight weight processes. Eachthreadis part of the same program but are scheduled individually.Until comparatively recently Linux just hadprocess 阅读全文