-
Notifications
You must be signed in to change notification settings - Fork 68
Fix possible race condition in topic common #769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import typing | ||
| import typing # noqa: F401 | ||
| import pytest | ||
|
|
||
| import ydb | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,21 +36,26 @@ def wrapper(rpc_state, response_pb, driver=None): | |
|
|
||
|
|
||
| def _get_shared_event_loop() -> asyncio.AbstractEventLoop: | ||
| global _shared_event_loop | ||
|
|
||
| if _shared_event_loop is not None: | ||
| return _shared_event_loop | ||
|
|
||
| with _shared_event_loop_lock: | ||
| if _shared_event_loop is not None: | ||
| return _shared_event_loop | ||
|
|
||
| event_loop_set_done: concurrent.futures.Future[asyncio.AbstractEventLoop] = concurrent.futures.Future() | ||
| loop_ready: threading.Event = threading.Event() | ||
|
|
||
| def start_event_loop(): | ||
| event_loop = asyncio.new_event_loop() | ||
| event_loop_set_done.set_result(event_loop) | ||
| asyncio.set_event_loop(event_loop) | ||
|
|
||
| def on_loop_started(): | ||
| # Set global only when loop is actually running | ||
| global _shared_event_loop | ||
| _shared_event_loop = event_loop | ||
| loop_ready.set() | ||
|
|
||
| event_loop.call_soon(on_loop_started) | ||
| event_loop.run_forever() | ||
|
|
||
| t = threading.Thread( | ||
|
|
@@ -60,7 +65,11 @@ def start_event_loop(): | |
| ) | ||
| t.start() | ||
|
|
||
| _shared_event_loop = event_loop_set_done.result() | ||
| loop_ready.wait() | ||
|
|
||
| if _shared_event_loop is None: | ||
| raise RuntimeError("Event loop was not properly initialized") | ||
|
|
||
| return _shared_event_loop | ||
|
Comment on lines
39
to
73
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,7 +77,7 @@ def __init__(self, timeout: float) -> None: | |
|
|
||
| def __eq__(self, other: object) -> bool: | ||
| return ( | ||
| type(self) == type(other) and isinstance(other, YdbRetryOperationSleepOpt) and self.timeout == other.timeout | ||
| type(self) is type(other) and isinstance(other, YdbRetryOperationSleepOpt) and self.timeout == other.timeout | ||
|
||
| ) | ||
|
|
||
| def __repr__(self) -> str: | ||
|
|
@@ -91,7 +91,7 @@ def __init__(self, result: Any) -> None: | |
|
|
||
| def __eq__(self, other: object) -> bool: | ||
| return ( | ||
| type(self) == type(other) | ||
| type(self) is type(other) | ||
| and isinstance(other, YdbRetryOperationFinalResult) | ||
|
||
| and self.result == other.result | ||
| and self.exc == other.exc | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.