Skip to content

Instantly share code, notes, and snippets.

View BafDyce's full-sized avatar

Fabian BafDyce

  • Austria, Vienna
View GitHub Profile
@BafDyce
BafDyce / recover_source_code.md
Created March 12, 2017 14:41 — forked from simonw/recover_source_code.md
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
""" Uses the posix_ipc module (https://pypi.python.org/pypi/posix_ipc) to
ensure that only one instance of the program is running. It catches all kind
of "errors" (namely Ctrl+C, SIGINT, SIGTERM, and any exception raised in the
program) in order to ensure no ressource leaks.
Probably works only on Linux (due to the posix_ipc library). """
#!/usr/bin/python3
import signal
import sys