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 functools import wraps | |
from twisted.internet import defer, reactor | |
from twisted.python import failure | |
class DeferTimeoutError(Exception): | |
pass | |
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 time | |
import asyncio | |
async def my_blocking_task(task_id): | |
print(f"running blocking {task_id}") | |
time.sleep(2) # faking cpu task | |
async def my_nonblocking_task(task_id): |
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 twisted.internet import defer, reactor, threads | |
@defer.inlineCallbacks | |
def problem(): | |
1 / 0 | |
yield 1 | |
@defer.inlineCallbacks |
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 datetime import datetime | |
from functools import wraps | |
from freezegun import freeze_time | |
from twisted.internet import defer, reactor, threads | |
def tx_freeze_time(*ft_args, **ft_kwargs): | |
def decorator(func): |
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 twisted.internet import reactor, defer | |
from twisted.web.client import Agent | |
def ping_google(): | |
agent = Agent(reactor) | |
d = agent.request("GET", "https://www.google.com/") | |
def check(response): | |
print("finish request") |
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 asyncio | |
from pprint import pprint | |
from concurrent.futures import ProcessPoolExecutor | |
import requests | |
def io_block_socket_call(url): | |
resp = url, requests.get(url).status_code == 200 | |
return resp |
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 asyncio | |
from pprint import pprint | |
import requests | |
def io_block_socket_call(url): | |
resp = url, requests.get(url).status_code == 200 | |
return resp |
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 functools import wraps | |
from flask import Flask, escape, request, make_response | |
app = Flask(__name__) | |
USERS = {"fabio": "12345", "italo": "abcde"} | |
def login_required(func): | |
@wraps(func) |
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 hashlib import md5 | |
import redis | |
class BloomFilterBaseBackend: | |
def initialize(self, size): | |
self.size = size | |
def validate(self, position): | |
if position < 0 or position >= self.size: |
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
In [82]: stdlib = set(open("stdlib").read().split("\n")) | |
In [83]: result = set() | |
In [84]: p = Path('.') |
NewerOlder