Skip to content

Instantly share code, notes, and snippets.

import site
import os
import pathlib
# Big thanks to Match on StackOverflow for helping me with this
# see https://stackoverflow.com/a/48713998/5614280
# This is some cool hackery to overwrite the default functionality of
# the builtin print function within you're entire python environment
# to display the file name and the line number as well as always flush
# the output. It works by creating a custom user script and placing it
@unux
unux / stream_stdout.py
Last active March 4, 2016 23:36 — forked from mattbornski/stdout.py
Streaming stdout from a Python subprocess in Python 2.6-2.7
#!/usr/bin/env python
# I was frustrated that no matter what buffer setting I passed to communicate,
# I could not get stdout from my subprocess until the process had completed.
# I googled around and came up with this, which illustrates the problem and a
# solution.
# http://stackoverflow.com/questions/2804543/read-subprocess-stdout-line-by-line
# http://bugs.python.org/issue3907
# http://docs.python.org/library/io.html
#!/bin/bash
#
# Give yourself a split view of your changes when you're committing
#
# If you patch hgext/record.py you can even show the changes you're
# cherry picking.
#
# Usage:
# HGEDITOR=~/bin/hg_ci_editor.sh hg ci ...
# HGEDITOR=~/bin/hg_ci_editor.sh hg record ...