# 异步 IO 当代码需要执行一个耗时的 IO 操作时,它只发出 IO 指令,并不等待 IO 结果,然后就去执行其他代码了。一段时间后,当 IO 返回结果时,再通知 CPU 进行处理。 异步 IO 模型需要一个消息循环,在消息循环中,主线程不断地重复 "读取消息 - 处理消息" 这一过程: 12345loop = get_event_loop()while True: event = loop.get_event() process_event(event) 消息模型其实早在应用在桌面应用程序中了。一个 GUI...

# 浏览器请求动态 web 页面过程 # WSGI WSGI:Web Server Gateway Interface。 WSGI 接口定义非常简单,它只要求 Web 开发者实现一个函数,就可以响应 HTTP 请求。 123def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html')]) return [b'Hello,...

# GIL GIL global interpreter lock (cpython),python 中一个线程对应 C 语言的一个线程 GIL 使得同一时刻只有一个线程在一个 CPU 上执行,无法将多个线程映射到多个 CPU 上执行 GIL 会根据执行的字节码行数以及时间片释放 GIL ,在遇到 IO 操作时也会主动释放 运行 12345678910import threading, multiprocessingdef loop(): x = 0 while True: x = x ^ 1for i in range(multiprocessing.cpu_count()): t =...

# ElementTree vs SAX and DOM SAX (simple API for XML) It functions as a stream parser, with an event-driven API. DOM (Document Object Model) It reads the XML into memory and converts it to objects that can be accessed with Python. ElementTree ElementTree is much easier to use, because it represents...

# GraphQL 特点 精确请求需要的数据,不多不少。例如: account 中有 name, sex, age 可以只取得需要的字段 name。 可以只用一个请求获取多个资源。 描述所有可能的类型系统,方便维护,可以根据需求平滑演进,添加或隐藏字段。 # GraphQL 与 restful 区别 restful 一个接口只能返回一个资源,graphql 一次可以获得多个资源 restful 使用不同 url 来区分资源,graphql 使用类型区分资源。 # GraphQL 参数类型 基本类型: String, Int, Float, Boolean, ID;可以在 schema...

# 基本用法 # Context 对象 Context 对象,表示一次对话的上下文(包括 HTTP 请求和 HTTP 回复) 123456789const Koa = require('koa')const app = new Koa()const main = ctx => { ctx.response.body = 'Hello World'}app.use(main)app.listen(3000) # HTTP Response 的类型 Koa 默认的返回类型是...

1234567891011121314151617181920212223242526272829303132Number.prototype.add = function (x) { return this + x;};Number.prototype.subtract = function (x) { return this - x;};Number.prototype.iterate = function () { var result = []; for (var i = 0; i...

javascript 对象创建方式 # prototype 12345678910function Cat() { this.name = "mm";}Cat.prototype.makeSound = function () { console.log("o(∩_∩)o");};var cat = new Cat();cat.makeSound(); #...