Skip to content

Instantly share code, notes, and snippets.

View 1st1's full-sized avatar

Yury Selivanov 1st1

View GitHub Profile
diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py
index aa2a5e8..6a6f868 100644
--- a/Lib/test/test_coroutines.py
+++ b/Lib/test/test_coroutines.py
@@ -497,17 +497,133 @@ class CoroutineTest(unittest.TestCase):
return self
def __aexit__(self, *e):
+ return 444
+
import asyncio
async def worker():
fut = asyncio.Future()
def setval():
print('setval')
fut.set_result(123)
print('setup')
@1st1
1st1 / httpget.py
Created September 8, 2015 16:05
a quick example of new async/await in python 3.5
import asyncio
async def http_get(domain):
reader, writer = await asyncio.open_connection(domain, 80)
writer.write(b'\r\n'.join([
b'GET / HTTP/1.1',
b'Host: %b' % domain.encode('latin-1'),
b'Connection: close',
b'', b''
@1st1
1st1 / gist:2029032
Created March 13, 2012 14:12
Alternate PEP 362 Implementation
##
# Copyright (c) 2011 Sprymix Inc.
# All rights reserved.
#
# See LICENSE for details.
##
import inspect
import collections
@1st1
1st1 / gist:2871349
Created June 4, 2012 22:58
pep 362 example
def render_signature(signature):
'''Renders function definition by its signature.
Example:
>>> def test(a:'foo', *, b:'bar', c=True, **kwargs:None) -> 'spam':
... pass
>>> render_signature(inspect.signature(test))
test(a:'foo', *, b:'bar', c=True, **kwargs:None) -> 'spam'
class _RedisPool(aioredis.RedisPool):
@asyncio.coroutine
def acquire(self):
# XXX
with (yield from self._cond):
while True:
yield from self._fill_free(override_min=True)
if self.freesize:
conn = self._pool.popleft()
if conn.closed:
# client.py
#
# Common client. Measure the response rate of the echo server
from socket import *
import time
from threading import Thread
import atexit
import sys
import asyncio
import uvloop
from socket import *
from uvloop.futures import Future as CFuture
import cProfile
import sys
import time
@1st1
1st1 / shell.py
Last active December 17, 2015 06:59
An extension for python REPL, inspired by PostgreSQL shell. Write '\e' to open an external editor for commands, '\r' to reset the buffer.
##
# Copyright 2013 Yury Selivanov <yselivanov@sprymix.com>
# License: MIT
##
import code
import subprocess
import os
import sys
import asyncio
import time
I = 0
def test2():
yield from ()
global I
I += 1