Skip to content

Commit

Permalink
set sticky bit on connection files
Browse files Browse the repository at this point in the history
avoids periodic cleanup of runtime directory
  • Loading branch information
minrk committed Sep 13, 2016
1 parent 38b81cc commit 97a0f83
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions jupyter_client/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import json
import os
import socket
import stat
import tempfile
import warnings
from getpass import getpass
Expand Down Expand Up @@ -135,6 +136,21 @@ def write_connection_file(fname=None, shell_port=0, iopub_port=0, stdin_port=0,
with open(fname, 'w') as f:
f.write(json.dumps(cfg, indent=2))

if hasattr(stat, 'S_ISVTX'):
# set the sticky bit to avoid periodic cleanup
permissions = os.stat(fname).st_mode
new_permissions = permissions | stat.S_ISVTX
if new_permissions != permissions:
try:
os.chmod(fname, permissions)
except OSError as e:
# failed to set sticky bit,
# probably not a big deal
warnings.warn(
"Failed to set sticky bit on %r: %s" % (fname, e),
RuntimeWarning,
)

return fname, cfg


Expand Down

0 comments on commit 97a0f83

Please sign in to comment.