after i updated my kernel, and i open my VM, that error came out, i always could find the way to fix it before, but there’s got easy way to fix it. so i want to write down this.
modprobe vboxdrv
modprobe vboxnetadp
modprobe vboxnetflt
after i updated my kernel, and i open my VM, that error came out, i always could find the way to fix it before, but there’s got easy way to fix it. so i want to write down this.
modprobe vboxdrv
modprobe vboxnetadp
modprobe vboxnetflt
Retrieve data from echo middleware, may cause you get code=400, message=EOF
error.
Context.Bind
only can bind once, after the request passed the middleware,the request data reader is running out, Context.Bind()
function read request body data from the socket buffer, once you took it out, it just gone
that’s why it returns EOF error.
func main() {
echoServer := echo.New()
echoServer.POST("/api", webfunc1, middleware1)
echoServer.Start(":8080")
}
func middleware1(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
// read origin body bytes
var bodyBytes []byte
if c.Request().Body != nil {
bodyBytes, _ = ioutil.ReadAll(c.Request().Body)
// write back to request body
c.Request().Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
// parse json data
reqData := struct {
ID string `json:"id"`
}{}
err := json.Unmarshal(bodyBytes, &reqData)
if err != nil {
return c.JSON(400, "error json.")
}
fmt.Println(reqData.ID)
}
return next(c)
}
}
func webfunc1(c echo.Context) error {
reqData := struct {
Data string `json:"data"`
}{}
c.Bind(&reqData)
fmt.Println(reqData.Data)
return c.HTML(200, "200 OK.")
}
Golang: Read from an io.ReadWriter without losing its content
before we talk about cert, we need to know how your browser contacts with web server using encrypted data while browsing. Continue reading what is Digital Cert used to?
克莱登大学科学家最新研究发现,植物不但有感觉,甚至还有幻觉,譬如一些韭菜就认为自己是人民,是大国梦参与者,是New时代受益者。
用了好几个月的centos虚拟机在某次断电中突然发现启动不起来了,出现类似metadata I/O error: block 0x1 ("xfs_trans_read_buf_map")
这样的错误, 该虚拟机的逻辑卷使用xfs分区格式
查阅了stackoverflow后,使用一条命令即解决了该问题 xfs_repair -v -L /dev/dm-0
打造一个帅气的监控需要什么:
你还看得见尸体旁的血吗? 看得见 在头颅旁 那你过几日再来瞧瞧吧 你还看得见尸体旁的血吗? 不是特别清晰 被昨夜的雨水冲刷了 那你过几日再瞧瞧吧 你还看得见尸体旁的血吗? 看不见了 被昨夜的雪覆盖了 那你还看得见尸体吗? 看得见 依稀还有人形 那你过几日再来瞧瞧吧 你还看得见尸体吗? 看不见了 被大雪覆盖了 最后的一点红被白雪覆盖了 像往常一样旷野一片寂静 大家似乎忘记了那里曾经死过人
出处未知
获取图片mime这种问题网上一搜就是mimetypes
的guess()
, 这种根据后缀判断文件类型的方式就有点曲线救国了,根据Ficapy介绍,unix上一般大多数的文件在开头都会有一串magic number(幻数),但不是所有文件都包含,根据幻数可以较准确判断出文件的类型 unix下允许使用后缀来标识文件类型,但实际上文件标不标后缀都是由开发者决定的
第一步,建立一个celery类的对象,传入一个名称(后续需要这个名称来执行异步任务), 配置消息代理,这里配置了本地redis服务器的第0个数据库
"""
tasks.py
"""
from celery import Celery
celery_app = Celery('name', broker='redis://localhost:6379/0')
那这样就可以通过task
装饰器来建立一个简单的异步任务了
"""
tasks.py
"""
import time
@celery_app.task
def task_name(someone):
time.sleep(5)
print('hello {}'.format(someone))
建立好异步任务之后,可以在外部调用这个任务
from tasks import task_name
# 任务用过delay方法可以传入参数,方法执行后并不会阻塞后续代码
task_name.delay('task')
print('start running!')
# 也可以不立即执行,可以先用s方法传入参数
task_name.s('task')
print('start running!')
task_name.delay()
对了执行celery命令celery -A name worker
, 执行后注册的任务会在console里面输出
想要delay的函数返回的结果就需要在建立celery对象中加入一个backend
参数
"""
tasks.py
"""
from celery import Celery
celery_app = Celery('name', broker='redis://localhost:6379/0', backend='redis://localhost:6379/1')
建立一个任务带返回数据功能的
"""
tasks.py
"""
import time
@celery_app.task
def say_hello(to):
time.sleep(5)
return "Hello {}".format(to)
通过ready()
方法可以获取任务是否完成,而get()
可以获取任务返回结果
from tasks import say_hello
import time
t = say_hello('hello')
while True:
r = t.ready()
if not r:
print("task done? {}".format(r))
continue
print('task done: {}'.format(t.get()))
break
下一篇详细讲讲Celery的Task类
迭代器学习的关键点在于区分iterator
与iterable
, iterator
代表一个对象是一个迭代器(可迭代对象), 而iterable
代表该对象可以被迭代 Continue reading Python迭代器&生成器