Skip to content

Instantly share code, notes, and snippets.

View miniyk2012's full-sized avatar
🏠
Working from home

Thomas Young miniyk2012

🏠
Working from home
View GitHub Profile
@miniyk2012
miniyk2012 / memory_leak_cross_reference.py
Created February 20, 2021 00:51
弱引用解决循环引用的内存泄漏
'''
内存泄漏循环引用的例子
https://www.jb51.net/article/200171.htm'''
import sys
import threading
import time
import gc
@miniyk2012
miniyk2012 / cookies_test.py
Created February 8, 2019 04:30
cookies_test
import requests
with requests.Session() as s:
jar = requests.cookies.RequestsCookieJar()
jar.set('tasty_cookie', 'yum')
s.cookies = jar
r = s.get('http://httpbin.org/cookies/set/sessioncookie/123456789')
print(r.history)
print(r.history[1].headers)
print(r.history[1].cookies) # 取的是响应中`Set-Cookie`的value, RequestsCookieJar对象
"""
http://docs.python-requests.org/en/master/user/advanced/#session-objects
When your app makes a connection to a server using a Session,
it keeps that connection around in a connection pool.
When your app wants to connect to the same server again,
it will reuse a connection from the pool rather than establishing a new one.
"""
import requests
@miniyk2012
miniyk2012 / concurrent_numpy.py
Created July 30, 2018 15:45
numpy并行运算
from time import time
from handythread import foreach
from multiprocessing.pool import Pool
import numpy as np
import math
def f(x):
# print(x)
y = [1]*10000000
[math.exp(i) for i in y]
print("how are you")