py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-06-25 10:35:27 +02:00
|
|
|
import os
|
|
|
|
import signal
|
|
|
|
import subprocess
|
2020-06-11 00:54:34 +02:00
|
|
|
import sys
|
|
|
|
import time
|
2019-01-15 02:09:15 +01:00
|
|
|
import types
|
2021-12-23 06:53:42 +01:00
|
|
|
from typing import Optional
|
2016-06-25 10:35:27 +02:00
|
|
|
|
2021-07-03 08:22:44 +02:00
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
|
2017-02-05 21:24:28 +01:00
|
|
|
# check for the venv
|
2021-07-03 08:22:44 +02:00
|
|
|
from tools.lib import sanity_check
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2017-02-05 21:24:28 +01:00
|
|
|
sanity_check.check_venv(__file__)
|
|
|
|
|
2017-02-19 22:18:18 +01:00
|
|
|
# TODO: Convert this to use scripts/lib/queue_workers.py
|
2016-06-25 10:35:27 +02:00
|
|
|
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
|
2021-02-12 08:20:45 +01:00
|
|
|
successful_worker_launch = "[process_queue] 15 queue worker threads were launched\n"
|
2016-06-25 10:35:27 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-11-13 03:24:14 +01:00
|
|
|
def check_worker_launch(run_dev: "subprocess.Popen[str]") -> bool:
|
2019-01-15 02:09:15 +01:00
|
|
|
failed = False
|
|
|
|
i = 0
|
2016-06-25 10:35:27 +02:00
|
|
|
|
2021-12-23 06:53:42 +01:00
|
|
|
def on_timer(signum: int, frame: Optional[types.FrameType]) -> None:
|
2019-01-15 02:09:15 +01:00
|
|
|
nonlocal failed, i
|
2021-02-12 08:20:45 +01:00
|
|
|
sys.stdout.write(".")
|
2016-06-25 10:35:27 +02:00
|
|
|
sys.stdout.flush()
|
2019-01-15 02:09:15 +01:00
|
|
|
i += 1
|
|
|
|
if i == 200:
|
|
|
|
failed = True
|
|
|
|
run_dev.send_signal(signal.SIGINT)
|
|
|
|
signal.setitimer(signal.ITIMER_REAL, 0, 0)
|
2018-01-01 07:38:28 +01:00
|
|
|
|
2019-01-15 02:09:15 +01:00
|
|
|
log_output = []
|
2021-02-12 08:20:45 +01:00
|
|
|
print("Polling run-dev", end="")
|
2019-01-15 02:09:15 +01:00
|
|
|
# Attempt to poll the log file for 60 sec. to see if all worker threads are launched.
|
|
|
|
old_handler = signal.signal(signal.SIGALRM, on_timer)
|
|
|
|
signal.setitimer(signal.ITIMER_REAL, 0.3, 0.3)
|
2020-04-18 03:55:04 +02:00
|
|
|
assert run_dev.stdout is not None
|
2019-01-15 02:09:15 +01:00
|
|
|
for line in run_dev.stdout:
|
|
|
|
log_output.append(line)
|
|
|
|
if line.endswith(successful_worker_launch):
|
2016-06-25 10:35:27 +02:00
|
|
|
break
|
2019-01-15 02:09:15 +01:00
|
|
|
else:
|
|
|
|
failed = True
|
|
|
|
signal.setitimer(signal.ITIMER_REAL, 0, 0)
|
|
|
|
signal.signal(signal.SIGALRM, old_handler)
|
2021-02-12 08:20:45 +01:00
|
|
|
sys.stdout.write("\n")
|
2016-06-25 10:35:27 +02:00
|
|
|
|
|
|
|
if not failed:
|
2021-02-12 08:20:45 +01:00
|
|
|
print("Worker threads launched successfully")
|
2016-06-25 10:35:27 +02:00
|
|
|
else:
|
2021-02-12 08:20:45 +01:00
|
|
|
print("Error in server startup. Dumping logs")
|
|
|
|
print("".join(log_output))
|
2018-01-01 07:38:28 +01:00
|
|
|
|
|
|
|
return failed
|
2016-06-25 10:35:27 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
if __name__ == "__main__":
|
2021-05-10 07:02:14 +02:00
|
|
|
print("\nStarting development server")
|
2023-03-04 02:17:54 +01:00
|
|
|
args = [f"{TOOLS_DIR}/run-dev"]
|
2019-01-15 02:09:15 +01:00
|
|
|
run_dev = subprocess.Popen(
|
|
|
|
args,
|
|
|
|
bufsize=1, # line buffered
|
2021-02-12 08:19:30 +01:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.STDOUT,
|
2022-01-22 07:52:54 +01:00
|
|
|
text=True,
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2019-01-15 02:09:15 +01:00
|
|
|
failed = check_worker_launch(run_dev)
|
2016-06-25 10:35:27 +02:00
|
|
|
|
2018-01-01 07:38:28 +01:00
|
|
|
if failed:
|
|
|
|
run_dev.send_signal(signal.SIGINT)
|
|
|
|
run_dev.wait()
|
|
|
|
sys.exit(1)
|
|
|
|
|
2018-02-06 06:58:55 +01:00
|
|
|
# In dev. environment, queues are run through Django's autoreload code. The
|
|
|
|
# autoreload code of Django works by looping over the files associated with
|
|
|
|
# all the loaded modules. This loop is run after every 1 second. If the
|
|
|
|
# file is found for the first time by the loop, it is assumed that the
|
2018-01-05 08:56:14 +01:00
|
|
|
# file is new and is not modified between the time it is loaded and is
|
|
|
|
# checked by the loop. This assumption is the source of a race condition.
|
|
|
|
|
|
|
|
# We can either implement a more sensitive version of the loop or we can
|
|
|
|
# just allow enough time to the Django loop to touch every file at least
|
|
|
|
# once.
|
2018-02-06 06:58:55 +01:00
|
|
|
time.sleep(1.3)
|
2016-06-25 10:35:27 +02:00
|
|
|
|
|
|
|
print("Attempting to modify a file")
|
2022-04-14 00:48:36 +02:00
|
|
|
os.utime("zerver/models.py")
|
2019-01-15 02:09:15 +01:00
|
|
|
failed = check_worker_launch(run_dev)
|
2016-06-25 10:35:27 +02:00
|
|
|
|
|
|
|
run_dev.send_signal(signal.SIGINT)
|
|
|
|
run_dev.wait()
|
2018-01-01 07:38:28 +01:00
|
|
|
if failed:
|
|
|
|
sys.exit(1)
|