Anton Patrushev

Create venv

Use apatrushev/get-venv-builder to create fresh empty virtualenv. This method independent from host environment as much as possible and works on both Python2 and Python3.

curl -L bit.ly/329DB9d | python -

Yeah, it is curl python so all your base are belong to us! In fact it is shortened version of:

curl https://raw.githubusercontent.com/apatrushev/get-venv-builder/master/clean.py | python -

Python getch

Pythons input/raw_input are not very suitable when you need to ask single letter question because user will have to press at least two keys. For that cases following snippet can be used. It is minimalistic unix only version of getch for python:

import sys
import termios
import tty

def getch():
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
        tty.setraw(sys.stdin.fileno())
        ch = sys.stdin.read(1)
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    return ch

getch()

asyncio vs ipdb workaround

ipdb do not work in asyncio applications (issue details). Core problem is quite twisted and probably will not be fixed for a long time. Workaround below helps to use ipdb with asyncio:

def threaded(func):
    def wrapper(*args, **kwargs):
        result = []
        def target():
            result.append(func(*args, **kwargs))
        thread = threading.Thread(target=target)
        thread.start()
        thread.join()
        return result[0]
    return wrapper
from IPython.terminal.debugger import TerminalPdb
TerminalPdb.cmdloop = threaded(TerminalPdb.cmdloop)