Skip to content

Instantly share code, notes, and snippets.

@pkubik
Created November 28, 2023 12:11
Show Gist options
  • Save pkubik/fcf388960dc1977320059b2460e35756 to your computer and use it in GitHub Desktop.
Save pkubik/fcf388960dc1977320059b2460e35756 to your computer and use it in GitHub Desktop.
Daemonized python interpreter
# setup FIFO and hang python interpreter
fifo_path=$TMPDIR/"pysh-"$(date +%s)
mkfifo $fifo_path
python3 <$fifo_path &
exec 3>$fifo_path
# perform some commands
echo 'import os' >$fifo_path
cat >$fifo_path <<EOF
import json
print(json.dumps(
{str(i): i for i in range(5)} | {"path": os.environ.get("PATH")},
indent=4,
))
EOF
# clean up
exec 3>&-
rm $fifo_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment