import_realm: Close the memcached connection before forking.

This prevents the memcached connection from being shared across
multiple processes, and hopefully addresses unexpected behavior from
cached functions like get_user_profile_by_id invoked inside the worker
processes.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-09-30 15:20:02 -07:00
committed by Tim Abbott
parent cf5ededa35
commit 46babbe9e1
2 changed files with 6 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ import boto3
import orjson
from bs4 import BeautifulSoup
from django.conf import settings
from django.core.cache import cache
from django.db import connection
from django.db.models import Max
from django.utils.timezone import now as timezone_now
@@ -759,6 +760,7 @@ def import_uploads(realm: Realm, import_dir: Path, processes: int, processing_av
process_avatars(record)
else:
connection.close()
cache._cache.disconnect_all()
with multiprocessing.Pool(processes) as p:
for out in p.imap_unordered(process_avatars, records):
pass