You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 7, 2023. It is now read-only.
# Make sure any older servers on port 8081 are killed.
84
+
ifIS_WINDOWS:
85
+
netstat_output=subprocess.run(
86
+
# Flags are:
87
+
#
88
+
# -n: Display addresses numerically. Looking up names is slow.
89
+
# -o: Include the PID for each connection.
90
+
["netstat", "-no"],
91
+
universal_newlines=True,
92
+
stdout=subprocess.PIPE,
93
+
).stdout
94
+
# Skip the first four lines, which are headings.
95
+
forconnectioninnetstat_output.splitlines()[4:]:
96
+
# Typical output is:
97
+
## Proto Local Address Foreign Address State PID
98
+
## TCP 127.0.0.1:1277 127.0.0.1:49971 ESTABLISHED 4624
99
+
proto, local_address, foreign_address, state, pid=connection.split()
100
+
pid=int(pid)
101
+
iflocal_address==HOST_ADDRESSandpid!=0:
102
+
os.kill(pid, 0)
103
+
else:
104
+
lsof_output=subprocess.run(
105
+
["lsof", "-i", ":{0}".format(PORT)],
106
+
universal_newlines=True,
107
+
stdout=subprocess.PIPE,
108
+
).stdout
109
+
forprocessinlsof_output.split("\n")[1:]:
110
+
data= [xforxinprocess.split(" ") ifx!=""]
111
+
iflen(data) <=1:
86
112
continue
87
113
ptokill=int(data[1])
88
114
mylogger.warn("Attempting to kill a stale runestone serve process: {}".format(ptokill))
89
115
os.kill(ptokill, signal.SIGKILL)
90
116
time.sleep(2) # give the old process a couple seconds to clear out
91
117
try:
92
118
os.kill(ptokill, 0) # will throw an Error if process gone
93
-
pytest.exit("Stale runestone server can't kill process: {}".format(ptokill))
119
+
pytest.exit(
120
+
"Stale runestone server can't kill process: {}".format(ptokill)
121
+
)
94
122
exceptProcessLookupError:
95
123
# The process was killed
96
124
pass
97
125
exceptPermissionError:
98
-
pytest.exit("Another server is using port {} process: {}".format(PORT, ptokill))
126
+
pytest.exit(
127
+
"Another server is using port {} process: {}".format(
128
+
PORT, ptokill
129
+
)
130
+
)
99
131
exceptException:
100
-
pytest.exit("Unknown error while trying to kill stale runestone server")
132
+
pytest.exit(
133
+
"Unknown error while trying to kill stale runestone server"
134
+
)
101
135
102
136
# Run the server. Simply calling ``runestone serve`` fails, since the process killed isn't the actual server, but probably a setuptools-created launcher.
103
137
self.runestone_server=subprocess.Popen(
@@ -107,7 +141,7 @@ def setUpModule(self):
107
141
# Testing time in dominated by browser startup/shutdown. So, simply run all tests in a module in a single browser instance to speed things up. See ``RunestoneTestCase.setUp`` for additional code to (mostly) clear the browser between tests.
108
142
#
109
143
# `PyVirtualDisplay <http://pyvirtualdisplay.readthedocs.io/en/latest/>`_ only runs on X-windows, meaning Linux. Mac seems to have `some support <https://support.apple.com/en-us/HT201341>`_. Windows is out of the question.
@@ -180,7 +214,7 @@ class RunestoneTestCase(unittest.TestCase):
180
214
defsetUp(self):
181
215
# Use the shared module-wide driver.
182
216
self.driver=mf.driver
183
-
self.host=HOST
217
+
self.host=HOST_URL
184
218
185
219
deftearDown(self):
186
220
# Clear as much as possible, to present an almost-fresh instance of a browser for the next test. (Shutting down then starting up a browswer is very slow.)
0 commit comments