Skip to content
This repository was archived by the owner on Sep 23, 2024. It is now read-only.

Commit 14b2215

Browse files
authored
Prevent 100% CPU utilisation while waiting in logical replication (#132)
1 parent ae9b211 commit 14b2215

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tap_postgres/sync_strategies/logical_replication.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import singer
99
import warnings
1010

11+
from select import select
1112
from psycopg2 import sql
1213
from singer import metadata, utils, get_bookmark
1314
from dateutil.parser import parse, UnknownTimezoneWarning, ParserError
@@ -660,6 +661,12 @@ def sync_tables(conn_info, logical_streams, state, end_lsn, state_file):
660661
state = singer.write_bookmark(state, s['tap_stream_id'], 'lsn', lsn_last_processed)
661662
singer.write_message(singer.StateMessage(value=copy.deepcopy(state)))
662663
lsn_processed_count = 0
664+
else:
665+
try:
666+
# Wait for a second unless a message arrives
667+
select([cur], [], [], 1)
668+
except InterruptedError:
669+
pass
663670

664671
# Every poll_interval, update latest comitted lsn position from the state_file
665672
if datetime.datetime.utcnow() >= (poll_timestamp + datetime.timedelta(seconds=poll_interval)):

0 commit comments

Comments
 (0)