自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(42)
  • 收藏
  • 关注

原创 nginx事件循环

2020-08-31 17:51:14 185

原创 socket 阻塞模型

import socketEOL1 = b'\n\n'EOL2 = b'\n\r\n'response = b'HTTP/1.0 200 OK\r\nDate: Mon, 1 Jan 1996 01:01:01 GMT\r\n'response += b'Content-Type: text/plain\r\nContent-Length: 13\r\n\r\n'response += b'Hello, world!'serversocket = socket.socket(socke..

2020-08-31 09:49:56 199

原创 python socket默认堵塞模型

socket 默认堵塞模型:服务端:node2:/root/python3#cat t22.py import socketimport timeEOL1 = b'\n\n'EOL2 = b'\n\r\n'response = b'HTTP/1.0 200 OK\r\nDate: Mon, 1 Jan 1996 01:01:01 GMT\r\n'response += b'Content-Type: text/plain\r\nContent-Length: 13\r\n\r\n'.

2020-08-31 09:37:07 205

原创 nginx 非堵塞事件驱动(异步)

2020-08-28 17:07:05 160

原创 openresty

openresty 是基于nginx的二次开发:1.包含C模块2.lua模块

2020-08-28 11:32:27 117

原创 nginx 反向代理

上游服务: upstream backend1 { server 192.168.137.3:9000 weight=10;server 192.168.137.3:8090 weight=10; }server{ listen 8090; server_name localhost; #ssl on; #从腾讯云获取到的第一个文件的全路径 ssl_certificate /etc..

2020-08-28 11:08:16 139

原创 nginx reopen nginx 日志

nginx reopen日志node2:/usr/local/nginx/logs#mv access.log access.log.20200828node2:/usr/local/nginx/logs#/usr/local/nginx/sbin/nginx -s reopen

2020-08-28 09:50:10 225

原创 python 垃圾回收

我们上节课提到过的,也是非常直观的一个想法,就是当这个对象的引用计数(指针数)为 0 的时候,说明这个对象永不可达,自然它也就成为了垃圾,需要被回收。node2:/root/python3#cat t20.py import osimport psutil# 显示当前 python 程序占用的内存大小def show_memory_info(hint): pid = os.getpid() p = psutil.Process(pid) info .

2020-08-27 10:22:48 158

原创 python asyncio

node2:/root/python3#cat t17.py import asyncioimport aiohttpimport timeasync def download_one(url): async with aiohttp.ClientSession() as session: async with session.get(url) as resp: print('Read {} from {}'.format(resp.content.

2020-08-26 11:46:56 128

原创 python 多线程爬虫

node2:/root/python3#cat t16.py import requestsimport timeimport threadingdef download_one(url): resp = requests.get(url) print(resp.content) #print('Read {} from {}'.format(len(resp.content), url))threads=[] def download_all(sites): .

2020-08-25 17:57:01 186

原创 python 爬虫1

node2:/root/python3#cat t16.py import requestsimport timedef download_one(url): resp = requests.get(url) print(resp.content) #print('Read {} from {}'.format(len(resp.content), url)) def download_all(sites): for site in sites: .

2020-08-25 17:36:34 119

原创 python 协程

node2:/root/python3#cat t15.py import asyncioasync def crawl_page(url): print('crawling {}'.format(url)) sleep_time = int(url.split('_')[-1]) await asyncio.sleep(sleep_time) print('OK {}'.format(url))async def main(urls): tasks =.

2020-08-24 15:12:44 115

原创 python 顺序调用

ef test111(req): #a=req.GET['a'] print 'xxxxxxxxxxxxxxxxxxxx' print req.scheme print req.get_full_path() print 'xxxxxxxxxxxxxxxxxxxx' a='1111111111111111' return HttpResponse(str(a))#@require_http_methods(["POST"])def test22.

2020-08-24 14:58:23 226

原创 nginx 事件循环

事件循环,就是宋朝加强的中央集权制。事件循环启动一个统一的调度器,让调度器来决定一个时刻去运行哪个任务,于是省却了多线程中启动线程、管理线程、同步锁等各种开销。同一时期的 NGINX,在高并发下能保持低资源低消耗高性能,相比 Apache 也支持更多的并发连接。...

2020-08-24 10:29:46 192

原创 python 迭代器

你肯定用过的容器、可迭代对象和迭代器python 中一切皆对象 列表(list: [0, 1, 2]),元组(tuple: (0, 1, 2)),字典(dict: {0:0, 1:1, 2:2}),集合(set: set([0, 1, 2]))都是容器哪些类型是可以迭代的呢?def is_iterable(param): try: iter(param) return True except TypeError: return..

2020-08-23 19:32:30 139

原创 简单的装饰器

简单的装饰器def my_decorator(func): def wrapper(): print('wrapper of decorator') func() return wrapperdef greet(): print('hello world')greet = my_decorator(greet)greet()这里的函数 my_decorator() 就是一个装饰器,它把真正需要执行的函数 greet() 包裹在其中.

2020-08-17 21:23:37 120 1

原创 pyhon pycharm项目结构

.├── proto│ ├── mat.py├── utils│ └── mat_mul.py└── src └── main.py node2:/root/python3#cat proto/mat.py # proto/mat.pyclass Matrix(object): def __init__(self, data): self.data = data self.n = len(data) self.m.

2020-08-15 09:27:42 1088

原创 python 2需要 __init__.py文件

python 2需要 __init__.py文件node2:/root/python3#python main.py Traceback (most recent call last): File "main.py", line 5, in <module> from utils.class_utils import *ImportError: No module named utils.class_utilsnode2:/root/python3#cd utils/n.

2020-08-15 09:16:55 179

原创 python 模块放在不同的目录

├── utils│ ├── utils.py│ └── class_utils.py├── src│ └── sub_main.py└── main.pynode2:/root/python3#cat utils/utils.py def get_sum(a, b): return a + b node2:/root/python3#cat utils/class_utils.py # utils/class_utils.pyclass Enco.

2020-08-15 09:14:06 204

原创 python 所有文件堆在一个目录下

项目模块化:from your_file import function_name, class_name 的方式调用node2:/root/python3/20200814#cat utils.py def get_sum(a, b): return a + bnode2:/root/python3/20200814#cat class_utils.py class Encoder(object): def encode(self, s): retur.

2020-08-14 16:00:22 150

原创 实现简单的搜索引擎<1>

class SearchEngineBase(object): def __init__(self): pass def add_corpus(self, file_path): with open(file_path, 'r') as fin: text = fin.read() self.process_corpus(file_path, text) def process_corpus(self, i.

2020-08-14 10:19:07 363

原创 面向对象<1>

# !/usr/bin/env python# -*- coding: utf-8 -*-class Document(): def __init__(self, title, author, context): print('init function called') self.title = title self.author = author self.__context = context # __开头的属性是私有属性.

2020-08-14 09:16:09 136

原创 filter 函数

接下来来看 filter(function, iterable) 函数,它和 map 函数类似,function 同样表示一个函数对象。filter() 函数表示对 iterable 中的每个元素,都使用 function 判断,并返回 True 或者 False,最后将返回 True 的元素组成一个新的可遍历的集合。# !/usr/bin/env python# -*- coding: utf-8 -*-l = [1, 2, 3, 4, 5]new_list = filter(l.

2020-08-13 22:30:34 2927

原创 python map函数

这里我简单解释一下。函数 map(function, iterable) 的第一个参数是函数对象,第二个参数是一个可以遍历的集合,它表示对 iterable 的每一个元素,都运用 function 这个函数。两者一对比,我们很明显地发现,lambda 函数让代码更加简洁明了。# !/usr/bin/env python# -*- coding: utf-8 -*-squared = map(lambda x: x**2, [1, 2, 3, 4, 5])print squared.

2020-08-13 22:27:57 129 1

原创 闭包

闭包:闭包其实和刚刚讲的嵌套函数类似,不同的是,这里外部函数返回的是一个函数,而不是一个具体的值。返回的函数通常赋于一个变量,这个变量可以在后面被继续执行调用。# !/usr/bin/env python# -*- coding: utf-8 -*-def nth_power(exponent): def exponent_of(base): return base ** exponent return exponent_of # 返回值是exponent_.

2020-08-13 21:35:08 131

原创 python exception 捕获

你也可以在 except 后面省略异常类型,这表示与任意异常相匹配(包括系统异常等):node2:/root/python3#cat t9.py try: s = input('please enter two numbers separated by comma: ') num1 = int(s.split(',')[0].strip()) num2 = int(s.split(',')[1].strip()) print(num1,num2) print(.

2020-08-13 15:23:39 127

原创 python 替换所有的非特殊字符

替换所有的字符:\w 匹配非特殊字符,即a-z、A-Z、0-9、_、汉字 node2:/root/python3#cat in.txtabc,jjd12,!3323$%%^&node2:/root/python3#cat t8.py import timeimport rewith open('in.txt', 'r') as fin: text = fin.read() text = re.sub(r'\w', ' ', text) print(.

2020-08-13 09:45:52 846

原创 super()函数

super(type[, object-or-type]) Return the superclass of type. If the second argument is omitted the super object returned is unbound. If the second argument is an object, isinstance(obj, type) must be true. If the second argument is a type, issubcl.

2020-08-11 11:37:48 151

原创 python3 一切皆对象

一切皆对象:所有基本类型内部均由对象实现。 一个整数是一个对象,一个字符串也是一个对象:>>> a='1'>>> print(type(a))<class 'str'>>>> a=1>>> print(type(a))<class 'int'>python 中类型也是一种对象,称为类型对象 >>> print(type(str))<class 'type'&g.

2020-08-10 16:29:47 157

原创 __new__方法

object.__new__(cls[, ...])调用来创建class cls的新的实例__new__()是一个静态方法(你不需要去定义它)它将请求实例的类作为第一个参数 剩下的参数是传递到对象构造器表达式返回的值应该是一个新的对象实例(通常是cls的实例)典型的实现创建一个类的实例通过调用superclass’s__new__()方法使用super().__new__(cls[, ...]) 使用适当的参数,然后修改新创建的实例如果__new__ 是被调用在对象构建和.

2020-08-07 15:15:11 286

原创 3.1. Objects, values and types

3.1. Objects, values and types对象,值和类型 对象是python的数据抽象。所有的数据在一个Python程序里是表现为对象或者对象之间的关系表示 每个对象有一个标识,一个类型和一个值 一个对象的标识一旦被创建后无法改变 你可以把对象当中内存中的地址 is 操作符是两个对象的标识比较id() 函数返回一个标识的整数>>> a='1'>>> b='1'>>> a is bTrue.

2020-08-07 10:15:45 216

原创 编译存储过程 library cache pin

SQL_ID 3cm6z3nnhzuykSQL_TEXT BEGIN MB_LIFE_PCKG_SYSTEM_LOGON.GET_BSNDEF_FLAG (:1 , :2 , :3 , :4 , :5 , :6 , :7 , :8 ) ; END;VERSION_COUNT 2LOADS 2HASH_VALUE 688909266ADDRESS 070000050AE83498PLAN_HASH_VALUE 0OLD_HASH_VALUE 1554650442LAST_ACTIVE_C.

2020-08-05 16:35:09 235

原创 __init__不是构造函数

__init__()方法又被称为构造器(constructor)。__init__ as a constructor?称其为类的构造函数是很诱人的但是不正确的,它是诱人的,因为它看起来像一个构造函数(按照惯例,__init__是类的第一个方法)它的行为类似于(它是在一个新创建的类实例的第一段代码)甚至听起来像一个(init 当然暗示了一种类似于构造函数的性质)不正确的,因为在调用__init__时对象已经被构造,你已经有一个正确的引用到一个类的实例Quote表明 ...

2020-08-05 08:57:54 511

原创 第2章 psutil模块

第2章 psutil模块:import psutilaa= psutil.net_connections('tcp')dict1 = []for x in aa: print x.statusimport psutilaa= psutil.net_connections('tcp')dict1 = {}# for x in aa:# print x.statusfor conn in aa: # dict1=[] try: dict1[conn.

2020-08-02 18:55:50 150

原创 python2和python3面向对象的区别

python 面向对象:node2:/root/python/20200729#cat t5.py # !/usr/bin/env python# -*- coding: utf-8 -*-class player(): ##定义一个类 def print_role(self): ##定义一个实例方法 return 'aaaaaaaa'print(type(player))print(dir(player))user1=player() ##类的实例化print.

2020-08-02 09:50:09 214

原创 构造对象

12.4 构造对象所有对象都是引用,但不是所有引用都是对象。一个引用不会作为对象运转,除非引用它的东西有特殊标记告诉Perl它属于哪个包。把一个引用和一个包名字标记起来的动作被称作赐福(blessing)你可以把赐福(bless)看作把一个引用转换成一个对象,尽管更准确地说是它把该引用转换成一个对象引用。bless 函数接收一个或者两个参数。第一个参数是一个引用,而第二个是要把引用赐福(bless)成的包。如果忽略第二个参数,则使用当前包。my $class = ref.

2020-08-02 09:35:09 163

原创 12.3.2 使用间接对象的方法调用

12.3.2 使用间接对象的方法调用 第二种风格的方法调用看起来象这样: METHOD INVOCANT (LIST) METHOD INVOCANT LIST METHOD INVOCANT$mage = summon Wizard "gandalf";speak $mage "You cannot pass";node1:/root/perl#cat x2.pl unshift (@INC,"/root/python"); require x1;use Data::D.

2020-08-02 09:21:19 131

原创 12.3.1 使用箭头操作符的方法调用

12.3.1 使用箭头操作符的方法调用print $ed->sum_var(1,5);print "\n";print $ed->{'a'};print "\n";~ INVOCANT->METHOD(LIST) INVOCANT->METHODrequire x1;use Data::Dumper;$ed = x1->new();当 INVOCANT 是一个包的名字的时候,我们把那个被调用的 METHOD 看作类方法。.

2020-08-02 09:11:08 123

原创 python 中的类和实例

# !/usr/bin/env python# -*- coding: utf-8 -*-class player(): ##定义一个类 def print_role(self): ##定义一个实例方法 return 'aaaaaaaa'print type(player)print dir(player)user1=player() ##类的实例化print type(user1)print dir(user1)print user1.print_role.

2020-08-01 19:00:06 111

原创 python __init__函数

python中的面向对象: # !/usr/bin/env python# -*- coding: utf-8 -*-class player(): ##定义一个类 # print '111111111111111' # #print self # print '111111111111111' def __init__(self,name,hp): ##__init__ print '11111111111111111111' ..

2020-08-01 18:51:52 190

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除