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
import multiprocessing | |
import os | |
import threading | |
import time | |
def child_thread(lock): | |
with lock: | |
time.sleep(10) |
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
#include <Python.h> | |
#include "stdio.h" | |
int main(int argc, char * argv[]){ | |
int i = 0; | |
PyTypeObject ptype, btype = PyType_Type, PyBaseObject_Type; | |
printf("i 0x%lx.\n", (unsigned long)&i); | |
printf("type name %s.\n", PyType_Type.tp_name); |
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
/* This is similar to PyObject_GenericGetAttr(), | |
but uses _PyType_Lookup() instead of just looking in type->tp_dict. */ | |
static PyObject * | |
type_getattro(PyTypeObject *type, PyObject *name) | |
{ | |
PyTypeObject *metatype = Py_TYPE(type); | |
PyObject *meta_attribute, *attribute; | |
descrgetfunc meta_get; | |
if (!PyUnicode_Check(name)) { |
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
/* Generic GetAttr functions - put these in your tp_[gs]etattro slot */ | |
PyObject * | |
_PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, PyObject *dict) | |
{ | |
PyTypeObject *tp = Py_TYPE(obj); | |
PyObject *descr = NULL; | |
PyObject *res = NULL; | |
descrgetfunc f; | |
Py_ssize_t dictoffset; |
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
// type object set attribute | |
static int | |
type_setattro(PyTypeObject *type, PyObject *name, PyObject *value) | |
{ | |
if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) { | |
PyErr_Format( | |
PyExc_TypeError, | |
"can't set attributes of built-in/extension type '%s'", | |
type->tp_name); |
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 concurrent.futures import ThreadPoolExecutor | |
import grpc | |
import pytest | |
import a_pb2_grpc | |
from rpc.server import AGRpcServer, BGRpcServer | |
import b_pb2_grpc | |
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 sqlalchemy.orm.base import instance_state | |
def get_instance_identity(instance, single=True): | |
"""获取实例主键值。""" | |
identity = instance_state(instance).identity | |
if single: | |
return identity[0] |
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
# install zlib | |
apt install zlib1g zlib1g-dev | |
# install pcre | |
apt install libpcre3 libpcre3-dev | |
# language zh-hans | |
apt install language-pack-zh-hans |
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
drop table if exists s_multi_update_same_row; | |
create table s_multi_update_same_row( | |
id int, | |
count int | |
); | |
insert into s_multi_update_same_row select id, 0 from generate_series(1, 1000) as id; | |
update s_multi_update_same_row A set count = count + 1 from generate_series(1, 10000) as B(id) where A.id = B.id % 1000 + 1; |
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
drop table if exists s_user_table; | |
create table s_user_table ( | |
id int, | |
user_id int | |
); | |
drop table if exists s_user_cnt_table; | |
create table s_user_cnt_table ( |