Skip to content

Commit b9f3ee5

Browse files
authored
Merge pull request #1066 from closeio/andrzej/p1/do-not-create-extra-thread-for-syncing
Do not create an extra thread to run sync
2 parents 9414157 + 6410c1d commit b9f3ee5

File tree

3 files changed

+20
-24
lines changed

3 files changed

+20
-24
lines changed

inbox/mailsync/backends/base.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,35 +76,32 @@ def _run(self): # type: ignore[no-untyped-def]
7676
raise
7777

7878
def _run_impl(self): # type: ignore[no-untyped-def]
79-
self.sync_thread = InterruptibleThread(
80-
retry_with_logging,
81-
self.sync,
82-
account_id=self.account_id,
83-
provider=self.provider_name,
84-
logger=self.log,
85-
)
86-
self.sync_thread.start()
87-
self.sync_thread.join()
88-
89-
if self.sync_thread.successful():
90-
self._cleanup()
79+
try:
80+
retry_with_logging(
81+
self.sync,
82+
account_id=self.account_id,
83+
provider=self.provider_name,
84+
logger=self.log,
85+
)
86+
except Exception:
87+
self.log.exception(
88+
"mail sync raised an exception", provider=self.provider_name
89+
)
90+
raise
91+
else:
9192
self.log.info(
9293
"mail sync finished successfully", provider=self.provider_name
9394
)
94-
return
95-
96-
self.log.error(
97-
"mail sync raised an exception",
98-
provider=self.provider_name,
99-
exc=self.sync_thread.exception,
100-
)
101-
raise self.sync_thread.exception # type: ignore[misc]
95+
finally:
96+
self._cleanup()
10297

10398
def sync(self) -> Never:
10499
raise NotImplementedError
105100

101+
def stop(self) -> None:
102+
raise NotImplementedError
103+
106104
def _cleanup(self) -> None:
107-
self.sync_thread.kill()
108105
with session_scope(self.namespace_id) as mailsync_db_session:
109106
for x in self.folder_monitors: # type: ignore[attr-defined]
110107
x.set_stopped(mailsync_db_session)

inbox/mailsync/backends/imap/monitor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,5 +217,4 @@ def stop(self) -> None:
217217
kill_all(self.folder_monitors, block=False)
218218
if isinstance(self, GmailSyncMonitor):
219219
kill_all(self.label_rename_handlers.values(), block=False)
220-
self.sync_thread.kill(block=False)
221-
self.join()
220+
self.kill()

inbox/mailsync/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def __init__( # type: ignore[no-untyped-def]
104104
)
105105

106106
self.syncing_accounts = set() # type: ignore[var-annotated]
107-
self.email_sync_monitors = {} # type: ignore[var-annotated]
107+
self.email_sync_monitors: dict[int, BaseMailSyncMonitor] = {}
108108
self.contact_sync_monitors = {} # type: ignore[var-annotated]
109109
self.event_sync_monitors = {} # type: ignore[var-annotated]
110110
# Randomize the poll_interval so we maintain at least a little fairness

0 commit comments

Comments
 (0)