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.
85
+
ifIS_WINDOWS:
86
+
netstat_output=subprocess.run(
87
+
# Flags are:
88
+
#
89
+
# -n: Display addresses numerically. Looking up names is slow.
90
+
# -o: Include the PID for each connection.
91
+
["netstat", "-no"],
92
+
universal_newlines=True,
93
+
stdout=subprocess.PIPE,
94
+
).stdout
95
+
# Skip the first four lines, which are headings.
96
+
forconnectioninnetstat_output.splitlines()[4:]:
97
+
# Typical output is:
98
+
## Proto Local Address Foreign Address State PID
99
+
## TCP 127.0.0.1:1277 127.0.0.1:49971 ESTABLISHED 4624
100
+
proto, local_address, foreign_address, state, pid=connection.split()
101
+
pid=int(pid)
102
+
iflocal_address==HOST_ADDRESSandpid!=0:
103
+
os.kill(pid, 0)
104
+
else:
105
+
lsof_output=subprocess.run(
106
+
["lsof", "-i", ":{0}".format(PORT)],
107
+
universal_newlines=True,
108
+
stdout=subprocess.PIPE,
109
+
).stdout
110
+
forprocessinlsof_output.split("\n")[1:]:
111
+
data= [xforxinprocess.split(" ") ifx!=""]
112
+
iflen(data) <=1:
86
113
continue
87
114
ptokill=int(data[1])
88
-
mylogger.warn("Attempting to kill a stale runestone serve process: {}".format(ptokill))
115
+
mylogger.warn(
116
+
"Attempting to kill a stale runestone serve process: {}".format(
117
+
ptokill
118
+
)
119
+
)
89
120
os.kill(ptokill, signal.SIGKILL)
90
-
time.sleep(2) # give the old process a couple seconds to clear out
121
+
time.sleep(2) # give the old process a couple seconds to clear out
91
122
try:
92
123
os.kill(ptokill, 0) # will throw an Error if process gone
93
-
pytest.exit("Stale runestone server can't kill process: {}".format(ptokill))
124
+
pytest.exit(
125
+
"Stale runestone server can't kill process: {}".format(ptokill)
126
+
)
94
127
exceptProcessLookupError:
95
128
# The process was killed
96
129
pass
97
130
exceptPermissionError:
98
-
pytest.exit("Another server is using port {} process: {}".format(PORT, ptokill))
131
+
pytest.exit(
132
+
"Another server is using port {} process: {}".format(
133
+
PORT, ptokill
134
+
)
135
+
)
99
136
exceptException:
100
-
pytest.exit("Unknown error while trying to kill stale runestone server")
137
+
pytest.exit(
138
+
"Unknown error while trying to kill stale runestone server"
139
+
)
101
140
102
141
# Run the server. Simply calling ``runestone serve`` fails, since the process killed isn't the actual server, but probably a setuptools-created launcher.
103
142
self.runestone_server=subprocess.Popen(
@@ -107,7 +146,7 @@ def setUpModule(self):
107
146
# 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
147
#
109
148
# `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 +219,7 @@ class RunestoneTestCase(unittest.TestCase):
180
219
defsetUp(self):
181
220
# Use the shared module-wide driver.
182
221
self.driver=mf.driver
183
-
self.host=HOST
222
+
self.host=HOST_URL
184
223
185
224
deftearDown(self):
186
225
# 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