##// END OF EJS Templates
copy utils.process.check_pid to html.utils...
Min RK -
Show More
@@ -78,7 +78,6 b' from IPython.kernel.zmq.session import Session'
78 from IPython.nbformat.sign import NotebookNotary
78 from IPython.nbformat.sign import NotebookNotary
79 from IPython.utils.importstring import import_item
79 from IPython.utils.importstring import import_item
80 from IPython.utils import submodule
80 from IPython.utils import submodule
81 from IPython.utils.process import check_pid
82 from IPython.utils.traitlets import (
81 from IPython.utils.traitlets import (
83 Dict, Unicode, Integer, List, Bool, Bytes, Instance,
82 Dict, Unicode, Integer, List, Bool, Bytes, Instance,
84 TraitError, Type,
83 TraitError, Type,
@@ -88,7 +87,7 b' from IPython.utils.path import filefind, get_ipython_dir'
88 from IPython.utils.sysinfo import get_sys_info
87 from IPython.utils.sysinfo import get_sys_info
89
88
90 from .nbextensions import SYSTEM_NBEXTENSIONS_DIRS
89 from .nbextensions import SYSTEM_NBEXTENSIONS_DIRS
91 from .utils import url_path_join
90 from .utils import url_path_join, check_pid
92
91
93 #-----------------------------------------------------------------------------
92 #-----------------------------------------------------------------------------
94 # Module globals
93 # Module globals
@@ -5,8 +5,10 b''
5
5
6 from __future__ import print_function
6 from __future__ import print_function
7
7
8 import errno
8 import os
9 import os
9 import stat
10 import stat
11 import sys
10
12
11 try:
13 try:
12 from urllib.parse import quote, unquote
14 from urllib.parse import quote, unquote
@@ -139,3 +141,30 b" def to_api_path(os_path, root=''):"
139 path = '/'.join(parts)
141 path = '/'.join(parts)
140 return path
142 return path
141
143
144
145 # Copy of IPython.utils.process.check_pid:
146
147 def _check_pid_win32(pid):
148 import ctypes
149 # OpenProcess returns 0 if no such process (of ours) exists
150 # positive int otherwise
151 return bool(ctypes.windll.kernel32.OpenProcess(1,0,pid))
152
153 def _check_pid_posix(pid):
154 """Copy of IPython.utils.pro"""
155 try:
156 os.kill(pid, 0)
157 except OSError as err:
158 if err.errno == errno.ESRCH:
159 return False
160 elif err.errno == errno.EPERM:
161 # Don't have permission to signal the process - probably means it exists
162 return True
163 raise
164 else:
165 return True
166
167 if sys.platform == 'win32':
168 check_pid = _check_pid_win32
169 else:
170 check_pid = _check_pid_posix
General Comments 0
You need to be logged in to leave comments. Login now