Uvicorn & Gunicorn
Uvicorn and GunicornUvicorn and Gunicorn are important concepts when developing applications in Python. However, there are many concepts to be aware of in order to fully understand Uvicorn and Gunicorn. The following is a brief summary of the necessary concepts, and the details will be dealt with separately later.Necessary ConceptsStarletteStarlette is a Web application server that can run asynchronously. Starlette runs on top of Uvicorn.FastAPIFastAPI provides many features on top of Starlet...
Gas optimization in Solidity, Ethereum
I’m sorry but my English is terrible. I hope you understand that generously.Recently, I was developing a toy project named Blind Market. It’s a simple P2P trading application using smart contract. I was making a contract using Solidity, and the trade stage proceeded in the order of pending, shipping, and done. The problem was appeared in done phase. The problem was that when I tried to close the transaction by paying the price raised by the seller in msg.value, the following error occurred.Pe...
P2WPKH
P2WPKHP2WPKH란 비트코인 내에서 가장 일반적인 스크립트 형식으로 비트코인 프로토콜에 대한 지불 거래 유형이다. 주소는 1로 시작하는데, 세그윗을 지원하는 새로운 주소 3 또는 bc1로 시작하는 주소보다 훨씬 비싸다. https://mirror.xyz/0xA1d9f681B25C14C1eE7B87f1CF102E73cA3ad4d9/egjhNVklgy_LgZmcTXXAOTBa6ePBqO3Ja9ZSoDIad-8 즉, 비트코인 주소가 1로 시작하면 P2PKH 주소를 사용하고 있는 것이다. 공개키의 간단한 해시이며, 이 해시를 주소로 사용하는 것이다. 이것은 원래 비트코인 주소 형식이었으며 오늘까지도 충실히 작동한다. 레거시 주소는 세그윗과 호환되지 않지만, 여전히 문제없이 P2PKH 주소에서 세그윗 주소로 BTC를 보낼 수 있다. 그러나 레거시 주소 트랜잭션이 더 크기 때문에 P2PKH 주소에서 전송하는 평균 속도는 세그윗 주소에서 전송할 때보다 더 높은 요금이 발생할 수 있다....
<100 subscribers
import time 간단한 문제에서 decorator의 쓰임을 찾아보자.
decorator => 함수를 input으로 받아서 => 새로운 함수를 만들어서 리턴
함수를 받아 새로운 함수를 리턴하는 함수
import time
def hello(name):
print("Hello, my name is " + name)
def track_time(func):
def new_func(*args, **kwargs):
start_time = time.time()
func(*args, **kwargs)
end_time = time.time()
print(f"Execute Time : {end_time - start_time}")
return new_func
hello = track_time(hello)
hello("primrose")
# ##
# 확장성을 위해 track_time이라는 데코레이터 함수를 만든다. 인자로 함수를 받고, 내부의 함수를 리턴해준다.
# 리턴되는 함수는 데코레이터 함수 안에서 정의된 함수이고, 확장성을 위해 packing한다.
"""
Hello, my name is primrose
Execute Time : 2.193450927734375e-05
"""
위에서 hello = track_time(hello)라는 식으로 함수를 wrapping했는데,
파이썬에서는 이것을 다음과 같이 표현이 가능하다
다음과 같이 `advanced_hello` 함수 위에 @track_time이라고 적으면 advanced_hello 함수를 인자로 받아서
track_time 함수가 decorate(장식)하여 새로운 함수가 반환된다.
이름은 advanced_hello 이지만 데코레이터가 있고 없고의 결과는 완전히 다르다.
@track_time
def advanced_hello(name):
print("Hello, my name is " + name)
advanced_hello("primrose")
"""
Hello, my name is primrose
Execute Time : 3.814697265625e-06
"""
위에서는 데코레이터가 하나였지만, 중첩(nested)도 가능하다.
시간을 측정하는 track_time뿐 아니라, 시작과 끝을 알려주는 데코레이터 함수도 만들었다.
def start(func):
print("start_func decorator applied")
def wrapper(*args, **kwargs):
print("function is called now")
return func(*args, **kwargs)
return wrapper
def finish(func):
print("finish_func decorator applied")
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
print("function is finished now")
return result
return wrapper
@track_time
@finish
@start
def nested_hello(name):
print("Hello, my name is " + name)
nested_hello("primrose")
"""
start_func decorator applied
finish_func decorator applied
function is called now
Hello, my name is primrose
function is finished now
Execute Time : 5.9604644775390625e-06
"""
아래는 간단한 데코레이터 활용 예시, 피보나치(엄연히 따지자면 메모이제이션)에서 사용 가능 !
def cache_memoization(func):
__cache = {}
def wrapper(*args):
if args in __cache:
return __cache[args]
else:
result = func(*args)
__cache.update({args: result})
return result
return wrapper
@cache_memoization
def fibo(n):
return n if n < 2 else fibo(n-1) + fibo(n-2)
fibo(100)
import time 간단한 문제에서 decorator의 쓰임을 찾아보자.
decorator => 함수를 input으로 받아서 => 새로운 함수를 만들어서 리턴
함수를 받아 새로운 함수를 리턴하는 함수
import time
def hello(name):
print("Hello, my name is " + name)
def track_time(func):
def new_func(*args, **kwargs):
start_time = time.time()
func(*args, **kwargs)
end_time = time.time()
print(f"Execute Time : {end_time - start_time}")
return new_func
hello = track_time(hello)
hello("primrose")
# ##
# 확장성을 위해 track_time이라는 데코레이터 함수를 만든다. 인자로 함수를 받고, 내부의 함수를 리턴해준다.
# 리턴되는 함수는 데코레이터 함수 안에서 정의된 함수이고, 확장성을 위해 packing한다.
"""
Hello, my name is primrose
Execute Time : 2.193450927734375e-05
"""
위에서 hello = track_time(hello)라는 식으로 함수를 wrapping했는데,
파이썬에서는 이것을 다음과 같이 표현이 가능하다
다음과 같이 `advanced_hello` 함수 위에 @track_time이라고 적으면 advanced_hello 함수를 인자로 받아서
track_time 함수가 decorate(장식)하여 새로운 함수가 반환된다.
이름은 advanced_hello 이지만 데코레이터가 있고 없고의 결과는 완전히 다르다.
@track_time
def advanced_hello(name):
print("Hello, my name is " + name)
advanced_hello("primrose")
"""
Hello, my name is primrose
Execute Time : 3.814697265625e-06
"""
위에서는 데코레이터가 하나였지만, 중첩(nested)도 가능하다.
시간을 측정하는 track_time뿐 아니라, 시작과 끝을 알려주는 데코레이터 함수도 만들었다.
def start(func):
print("start_func decorator applied")
def wrapper(*args, **kwargs):
print("function is called now")
return func(*args, **kwargs)
return wrapper
def finish(func):
print("finish_func decorator applied")
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
print("function is finished now")
return result
return wrapper
@track_time
@finish
@start
def nested_hello(name):
print("Hello, my name is " + name)
nested_hello("primrose")
"""
start_func decorator applied
finish_func decorator applied
function is called now
Hello, my name is primrose
function is finished now
Execute Time : 5.9604644775390625e-06
"""
아래는 간단한 데코레이터 활용 예시, 피보나치(엄연히 따지자면 메모이제이션)에서 사용 가능 !
def cache_memoization(func):
__cache = {}
def wrapper(*args):
if args in __cache:
return __cache[args]
else:
result = func(*args)
__cache.update({args: result})
return result
return wrapper
@cache_memoization
def fibo(n):
return n if n < 2 else fibo(n-1) + fibo(n-2)
fibo(100)
Uvicorn & Gunicorn
Uvicorn and GunicornUvicorn and Gunicorn are important concepts when developing applications in Python. However, there are many concepts to be aware of in order to fully understand Uvicorn and Gunicorn. The following is a brief summary of the necessary concepts, and the details will be dealt with separately later.Necessary ConceptsStarletteStarlette is a Web application server that can run asynchronously. Starlette runs on top of Uvicorn.FastAPIFastAPI provides many features on top of Starlet...
Gas optimization in Solidity, Ethereum
I’m sorry but my English is terrible. I hope you understand that generously.Recently, I was developing a toy project named Blind Market. It’s a simple P2P trading application using smart contract. I was making a contract using Solidity, and the trade stage proceeded in the order of pending, shipping, and done. The problem was appeared in done phase. The problem was that when I tried to close the transaction by paying the price raised by the seller in msg.value, the following error occurred.Pe...
P2WPKH
P2WPKHP2WPKH란 비트코인 내에서 가장 일반적인 스크립트 형식으로 비트코인 프로토콜에 대한 지불 거래 유형이다. 주소는 1로 시작하는데, 세그윗을 지원하는 새로운 주소 3 또는 bc1로 시작하는 주소보다 훨씬 비싸다. https://mirror.xyz/0xA1d9f681B25C14C1eE7B87f1CF102E73cA3ad4d9/egjhNVklgy_LgZmcTXXAOTBa6ePBqO3Ja9ZSoDIad-8 즉, 비트코인 주소가 1로 시작하면 P2PKH 주소를 사용하고 있는 것이다. 공개키의 간단한 해시이며, 이 해시를 주소로 사용하는 것이다. 이것은 원래 비트코인 주소 형식이었으며 오늘까지도 충실히 작동한다. 레거시 주소는 세그윗과 호환되지 않지만, 여전히 문제없이 P2PKH 주소에서 세그윗 주소로 BTC를 보낼 수 있다. 그러나 레거시 주소 트랜잭션이 더 크기 때문에 P2PKH 주소에서 전송하는 평균 속도는 세그윗 주소에서 전송할 때보다 더 높은 요금이 발생할 수 있다....
Share Dialog
Share Dialog
No comments yet