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 sys
|
|
|
|
import time
|
|
|
|
import signal
|
|
|
|
import subprocess
|
2019-01-15 02:09:15 +01:00
|
|
|
import types
|
2016-06-25 10:35:27 +02:00
|
|
|
|
2017-02-05 21:24:28 +01:00
|
|
|
# check for the venv
|
|
|
|
from lib import sanity_check
|
|
|
|
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__))
|
2020-05-08 16:37:58 +02:00
|
|
|
successful_worker_launch = '[process_queue] 16 queue worker threads were launched\n'
|
2016-06-25 10:35:27 +02: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
|
|
|
|
2019-01-15 02:09:15 +01:00
|
|
|
def on_timer(signum: int, frame: types.FrameType) -> None:
|
|
|
|
nonlocal failed, i
|
2016-06-25 10:35:27 +02:00
|
|
|
sys.stdout.write('.')
|
|
|
|
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 = []
|
|
|
|
print("Polling run-dev", end='')
|
|
|
|
# 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)
|
2016-06-25 10:35:27 +02:00
|
|
|
sys.stdout.write('\n')
|
|
|
|
|
|
|
|
if not failed:
|
2017-01-12 05:45:20 +01:00
|
|
|
print('Worker threads launched successfully')
|
2016-06-25 10:35:27 +02:00
|
|
|
else:
|
|
|
|
print('Error in server startup. Dumping logs')
|
2018-01-01 07:38:28 +01:00
|
|
|
print(''.join(log_output))
|
|
|
|
|
|
|
|
return failed
|
2016-06-25 10:35:27 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
print('\nStarting Development Server')
|
|
|
|
args = ["{}/run-dev.py".format(TOOLS_DIR)]
|
2019-01-15 02:09:15 +01:00
|
|
|
run_dev = subprocess.Popen(
|
|
|
|
args,
|
|
|
|
bufsize=1, # line buffered
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
|
|
|
universal_newlines=True)
|
|
|
|
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")
|
2018-07-18 23:50:16 +02:00
|
|
|
os.utime('zerver/lib/actions.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)
|