-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restart kernel daemon when non-package Python modules change
- Loading branch information
Showing
4 changed files
with
44 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,30 @@ | ||
|
||
# reset state | ||
%reset | ||
|
||
import sys | ||
import types | ||
import os | ||
import json | ||
|
||
# NOTE: the kernel_deps code is repeated in the setup.py file | ||
# (we can't easily share this code b/c of the way it is run). | ||
# If you edit this code also edit the same code in setup.py! | ||
|
||
kernel_deps = dict() | ||
for module in list(sys.modules.values()): | ||
# Some modules play games with sys.modules (e.g. email/__init__.py | ||
# in the standard library), and occasionally this can cause strange | ||
# failures in getattr. Just ignore anything that's not an ordinary | ||
# module. | ||
if not isinstance(module, types.ModuleType): | ||
continue | ||
path = getattr(module, "__file__", None) | ||
if not path: | ||
continue | ||
if path.endswith(".pyc") or path.endswith(".pyo"): | ||
path = path[:-1] | ||
if not os.path.exists(path): | ||
continue | ||
kernel_deps[path] = os.stat(path).st_mtime | ||
print(json.dumps(kernel_deps)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters