Skip to content

Commit 969dec1

Browse files
authored
fix: PrintBuffer logic (#336)
Signed-off-by: Artem Inzhyyants <[email protected]>
1 parent 0895115 commit 969dec1

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

airbyte_cdk/entrypoint.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from airbyte_cdk.connector import TConfig
2424
from airbyte_cdk.exception_handler import init_uncaught_exception_handler
25-
from airbyte_cdk.logger import init_logger
25+
from airbyte_cdk.logger import PRINT_BUFFER, init_logger
2626
from airbyte_cdk.models import (
2727
AirbyteConnectionStatus,
2828
AirbyteMessage,
@@ -337,11 +337,11 @@ def launch(source: Source, args: List[str]) -> None:
337337
parsed_args = source_entrypoint.parse_args(args)
338338
# temporarily removes the PrintBuffer because we're seeing weird print behavior for concurrent syncs
339339
# Refer to: https://github.com/airbytehq/oncall/issues/6235
340-
# with PrintBuffer():
341-
for message in source_entrypoint.run(parsed_args):
342-
# simply printing is creating issues for concurrent CDK as Python uses different two instructions to print: one for the message and
343-
# the other for the break line. Adding `\n` to the message ensure that both are printed at the same time
344-
print(f"{message}\n", end="", flush=True)
340+
with PRINT_BUFFER:
341+
for message in source_entrypoint.run(parsed_args):
342+
# simply printing is creating issues for concurrent CDK as Python uses different two instructions to print: one for the message and
343+
# the other for the break line. Adding `\n` to the message ensure that both are printed at the same time
344+
print(f"{message}\n", end="")
345345

346346

347347
def _init_internal_request_filter() -> None:

airbyte_cdk/logger.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
Level,
1717
Type,
1818
)
19+
from airbyte_cdk.utils import PrintBuffer
1920
from airbyte_cdk.utils.airbyte_secrets_utils import filter_secrets
2021

22+
PRINT_BUFFER = PrintBuffer(flush_interval=0.1)
23+
2124
LOGGING_CONFIG = {
2225
"version": 1,
2326
"disable_existing_loggers": False,
@@ -27,7 +30,7 @@
2730
"handlers": {
2831
"console": {
2932
"class": "logging.StreamHandler",
30-
"stream": "ext://sys.stdout",
33+
"stream": PRINT_BUFFER,
3134
"formatter": "airbyte",
3235
},
3336
},

0 commit comments

Comments
 (0)