This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-------------------------- | |
Kafka核心概念 | | |
-------------------------- | |
# Broker | |
* 一台Kafka服务器,负责消息的读,写,存 | |
* 一个集群由多个Broker组成,一个Broker可以容纳多个Topic | |
* Broker与Broker之间 不存在 M/S(主从)的关系 | |
# Topic | |
* 同一个Topic的消息可以分布在一个或者多个节点上 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TCPClient: | |
def __init__(self): | |
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
def connect(self, host, port): | |
'''链接Server端''' | |
self.sock.connect((host, port)) | |
def send(self, data): | |
'''将数据发送到Server端''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\s 匹配空白字符 | |
\w 匹配任意字母/数字/下划线 | |
\W 和小写 w 相反,匹配任意字母/数字/下划线以外的字符 | |
\d 匹配十进制数字 | |
\D 匹配除了十进制数以外的值 | |
[0-9] 匹配一个0-9之间的数字 | |
[a-z] 匹配小写英文字母 | |
[A-Z] 匹配大写英文字母 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tree(object): | |
def __init__(self, data): | |
self.data = data | |
self.root_node = [] | |
self.common_node = {} | |
self.tree = [] | |
def get_root_nodes(self) -> list: | |
""" | |
遍历data查找根节点 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
1 当指定异常被引发时,使用on_exception装饰器重试。这里有一个例子,当出现任何requests异常时,使用指数退避(backoff.expo即退避时间指数增长): | |
2 当目标函数返回值符合某个特定条件时,on_predicate装饰器会安排重试。当为外部生成内容轮询资源时可能有用。 | |
3 两个backoff装饰器都可以选择使用关键字参数on_success、on_backoff和on_giveup接受事件处理程序函数。这在报告统计或执行其他自定义日志方面可能有用。 | |
''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 单行注释 | |
/* 多行 | |
注释 */ | |
// 导入包的子句在每个源文件的开头。 | |
// Main比较特殊,它用来声明可执行文件,而不是一个库。 | |
package main | |
// Import语句声明了当前文件引用的包。 | |
import ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RWLock(object): | |
def __init__(self): | |
self.lock = threading.Lock() | |
self.rcond = threading.Condition(self.lock) | |
self.wcond = threading.Condition(self.lock) | |
self.read_waiter = 0 # 等待获取读锁的线程数 | |
self.write_waiter = 0 # 等待获取写锁的线程数 | |
self.state = 0 # 正数:表示正在读操作的线程数 负数:表示正在写操作的线程数(最多-1) | |
self.owners = [] # 正在操作的线程id集合 | |
self.write_first = True # 默认写优先,False表示读优先 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 表结构 | |
-- * 学生表student(id,name) | |
-- * 课程表course(id,name) | |
-- * 学生课程表student_course(sid,cid,score) | |
create table student( | |
id int unsigned primary key auto_increment, | |
name char(10) not null | |
); | |
insert into student(name) values('张三'),('李四'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import Timer | |
def hello(): | |
print("hello") | |
class RepeatingTimer(Timer): | |
''' | |
RepeatingTimer 的 run 方法会一直执行 while 循环体,在循环体了会执行用户传入的 function 对象,并等待指定的时间。当用户想退出定时器时,只需要调用 cancel 方法,将 flag 置为 True 便不会继续执行循环体了。这样便完成了一个还不错的循环定时器。 | |
''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Queue import PriorityQueue | |
from datetime import datetime | |
import threading | |
class Delayed(object): | |
# 返回:计划执行时间 | |
# 单位: datetime | |
def plan_time(self): | |
pass |