Skip to content

Commit 97a0f83

Browse files
committed
set sticky bit on connection files
avoids periodic cleanup of runtime directory
1 parent 38b81cc commit 97a0f83

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

jupyter_client/connect.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import json
1515
import os
1616
import socket
17+
import stat
1718
import tempfile
1819
import warnings
1920
from getpass import getpass
@@ -135,6 +136,21 @@ def write_connection_file(fname=None, shell_port=0, iopub_port=0, stdin_port=0,
135136
with open(fname, 'w') as f:
136137
f.write(json.dumps(cfg, indent=2))
137138

139+
if hasattr(stat, 'S_ISVTX'):
140+
# set the sticky bit to avoid periodic cleanup
141+
permissions = os.stat(fname).st_mode
142+
new_permissions = permissions | stat.S_ISVTX
143+
if new_permissions != permissions:
144+
try:
145+
os.chmod(fname, permissions)
146+
except OSError as e:
147+
# failed to set sticky bit,
148+
# probably not a big deal
149+
warnings.warn(
150+
"Failed to set sticky bit on %r: %s" % (fname, e),
151+
RuntimeWarning,
152+
)
153+
138154
return fname, cfg
139155

140156

0 commit comments

Comments
 (0)