mirror of https://github.com/zulip/zulip.git
python: Simplify stdio flushing using print(…, flush=True).
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
d8adeb66ca
commit
342834ee9c
|
@ -198,9 +198,9 @@ def get_deployment_lock(error_rerun_script: str) -> None:
|
|||
WARNING
|
||||
+ "Another deployment in progress; waiting for lock... "
|
||||
+ "(If no deployment is running, rmdir {})".format(LOCK_DIR)
|
||||
+ ENDC
|
||||
+ ENDC,
|
||||
flush=True,
|
||||
)
|
||||
sys.stdout.flush()
|
||||
time.sleep(3)
|
||||
|
||||
if not got_lock:
|
||||
|
|
|
@ -78,18 +78,17 @@ def test_server_running(
|
|||
|
||||
try:
|
||||
# Wait for the server to start up.
|
||||
sys.stdout.write("\nWaiting for test server (may take a while)")
|
||||
print(end="\nWaiting for test server (may take a while)")
|
||||
if not dots:
|
||||
sys.stdout.write("\n\n")
|
||||
print("\n", flush=True)
|
||||
t = time.time()
|
||||
while not server_is_up(server, log_file):
|
||||
if dots:
|
||||
sys.stdout.write(".")
|
||||
sys.stdout.flush()
|
||||
print(end=".", flush=True)
|
||||
time.sleep(0.4)
|
||||
if time.time() - t > MAX_SERVER_WAIT:
|
||||
raise Exception("Timeout waiting for server")
|
||||
sys.stdout.write("\n\n--- SERVER IS UP! ---\n\n")
|
||||
print("\n\n--- SERVER IS UP! ---\n", flush=True)
|
||||
|
||||
# DO OUR ACTUAL TESTING HERE!!!
|
||||
yield
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
from argparse import ArgumentParser
|
||||
from typing import Any
|
||||
|
@ -207,8 +206,7 @@ class Command(ZulipBaseCommand):
|
|||
do_deactivate_realm(realm, acting_user=None)
|
||||
|
||||
def percent_callback(bytes_transferred: Any) -> None:
|
||||
sys.stdout.write(".")
|
||||
sys.stdout.flush()
|
||||
print(end=".", flush=True)
|
||||
|
||||
# Allows us to trigger exports separately from command line argument parsing
|
||||
export_realm_wrapper(
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
# Generated by Django 1.11.13 on 2018-06-14 13:39
|
||||
|
||||
import sys
|
||||
|
||||
import bitfield.models
|
||||
from django.db import migrations
|
||||
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
|
||||
|
@ -19,8 +17,7 @@ def reset_is_private_flag(apps: StateApps, schema_editor: DatabaseSchemaEditor)
|
|||
|
||||
i = 0
|
||||
total = len(user_profile_ids)
|
||||
print("Setting default values for the new flag...")
|
||||
sys.stdout.flush()
|
||||
print("Setting default values for the new flag...", flush=True)
|
||||
for user_id in user_profile_ids:
|
||||
while True:
|
||||
# Ideally, we'd just do a single database query per user.
|
||||
|
@ -45,8 +42,7 @@ def reset_is_private_flag(apps: StateApps, schema_editor: DatabaseSchemaEditor)
|
|||
i += 1
|
||||
if i % 50 == 0 or i == total:
|
||||
percent = round((i / total) * 100, 2)
|
||||
print(f"Processed {i}/{total} {percent}%")
|
||||
sys.stdout.flush()
|
||||
print(f"Processed {i}/{total} {percent}%", flush=True)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import sys
|
||||
|
||||
from django.db import migrations
|
||||
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
|
||||
from django.db.migrations.state import StateApps
|
||||
|
@ -19,8 +17,7 @@ def set_initial_value_of_is_private_flag(
|
|||
total = Message.objects.filter(recipient__type__in=[1, 3]).count()
|
||||
processed = 0
|
||||
|
||||
print("\nStart setting initial value for is_private flag...")
|
||||
sys.stdout.flush()
|
||||
print("\nStart setting initial value for is_private flag...", flush=True)
|
||||
while True:
|
||||
range_end = i + 10000
|
||||
# Can't use [Recipient.PERSONAL, Recipient.HUDDLE] in migration files
|
||||
|
@ -41,8 +38,7 @@ def set_initial_value_of_is_private_flag(
|
|||
percent = round((processed / total) * 100, 2)
|
||||
else:
|
||||
percent = 100.00
|
||||
print(f"Processed {processed}/{total} {percent}%")
|
||||
sys.stdout.flush()
|
||||
print(f"Processed {processed}/{total} {percent}%", flush=True)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
# and zerver/lib/data_types.py systems for validating the schemas of
|
||||
# events; it also uses the OpenAPI tools to validate our documentation.
|
||||
import copy
|
||||
import sys
|
||||
import time
|
||||
from io import StringIO
|
||||
from typing import Any, Callable, Dict, List, Optional, Set
|
||||
|
@ -389,10 +388,10 @@ class BaseAction(ZulipTestCase):
|
|||
we apply events after fetching data. If you
|
||||
do not know how to debug it, you can ask for
|
||||
help on chat.
|
||||
"""
|
||||
""",
|
||||
flush=True,
|
||||
)
|
||||
|
||||
sys.stdout.flush()
|
||||
raise AssertionError("Mismatching states")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue