Skip to content

Commit 1b8b87c

Browse files
committed
FIX: Fix for windows workflows
1 parent 4dac2b0 commit 1b8b87c

File tree

12 files changed

+125
-147
lines changed

12 files changed

+125
-147
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626

2727
- name: Install poetry
2828
run: |
29-
python -m pip install --upgrade pip poetry==1.3.2
29+
python -m pip install --upgrade pip poetry==1.5.1
3030
3131
- name: Prepare release
3232
id: vars
@@ -62,7 +62,7 @@ jobs:
6262

6363
- name: Install poetry
6464
run: |
65-
python -m pip install --upgrade pip poetry==1.3.2
65+
python -m pip install --upgrade pip poetry==1.5.1
6666
6767
- name: Build
6868
run: |

.github/workflows/test.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,21 @@ jobs:
2323
python-version: ${{ matrix.python-version }}
2424

2525
- name: Install poetry
26-
run: python -m pip install --upgrade pip poetry==1.3.2
27-
28-
- name: Load cached venv
29-
id: cached-poetry-dependencies
30-
uses: actions/cache@v3
31-
with:
32-
path: .venv
33-
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
26+
run: python -m pip install --upgrade pip poetry==1.5.1
3427

3528
- name: Install dependencies
3629
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
3730
run: scripts/build.sh
31+
shell: bash
3832

3933
- name: Run tests in release mode
34+
timeout-minutes: 5
4035
if: ${{ github.ref == 'refs/heads/main' }}
4136
run: scripts/test.sh --release
37+
shell: bash
38+
4239
- name: Run tests
40+
timeout-minutes: 5
4341
if: ${{ github.ref != 'refs/heads/main' }}
4442
run: scripts/test.sh
43+
shell: bash

databento/live/client.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ def __next__(self) -> DBNRecord:
128128
if self._dbn_queue is None:
129129
raise ValueError("iteration has not started")
130130

131-
while not self._session.is_disconnected() or not self._dbn_queue.empty():
131+
while not self._session.is_disconnected() or self._dbn_queue.qsize() > 0:
132132
try:
133-
record = self._dbn_queue.get(timeout=0.001)
134-
except (futures.TimeoutError, queue.Empty):
133+
record = self._dbn_queue.get(block=False)
134+
except queue.Empty:
135135
continue
136136
else:
137137
logger.debug(
@@ -476,9 +476,6 @@ def block_for_close(
476476
wait_for_close
477477
478478
"""
479-
if not self.is_connected():
480-
return
481-
482479
try:
483480
asyncio.run_coroutine_threadsafe(
484481
self._shutdown(),
@@ -520,9 +517,6 @@ async def wait_for_close(
520517
block_for_close
521518
522519
"""
523-
if not self.is_connected():
524-
return
525-
526520
waiter = asyncio.wrap_future(
527521
asyncio.run_coroutine_threadsafe(
528522
self._shutdown(),
@@ -549,5 +543,4 @@ async def _shutdown(self) -> None:
549543
"""
550544
if self._session is None:
551545
return
552-
self._dataset = "" # reset dataset for client reuse
553546
await self._session.wait_for_close()

databento/live/session.py

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@
33
import logging
44
import queue
55
import struct
6-
import threading
76
from typing import IO, Callable, Iterable, List, Optional, Set, Union
87

98
import databento_dbn
109

11-
from databento.common.enums import Dataset, Schema, SType
10+
from databento.common.enums import Dataset
11+
from databento.common.enums import Schema
12+
from databento.common.enums import SType
1213
from databento.common.error import BentoError
1314
from databento.common.symbology import ALL_SYMBOLS
14-
from databento.live import AUTH_TIMEOUT_SECONDS, CONNECT_TIMEOUT_SECONDS, DBNRecord
15+
from databento.live import AUTH_TIMEOUT_SECONDS
16+
from databento.live import CONNECT_TIMEOUT_SECONDS
17+
from databento.live import DBNRecord
1518
from databento.live.protocol import DatabentoLiveProtocol
1619

20+
1721
logger = logging.getLogger(__name__)
1822

1923

@@ -258,7 +262,6 @@ def __init__(
258262
self._ts_out = ts_out
259263
self._protocol_factory = protocol_factory
260264

261-
self._lock = threading.Lock()
262265
self._transport: Optional[asyncio.Transport] = None
263266
self._protocol: Optional[_SessionProtocol] = None
264267

@@ -276,12 +279,11 @@ def is_authenticated(self) -> bool:
276279
"""
277280
if self._protocol is None:
278281
return False
279-
with self._lock:
280-
try:
281-
self._protocol.authenticated.result()
282-
except (asyncio.InvalidStateError, asyncio.CancelledError, BentoError):
283-
return False
284-
return True
282+
try:
283+
self._protocol.authenticated.result()
284+
except (asyncio.InvalidStateError, asyncio.CancelledError, BentoError):
285+
return False
286+
return True
285287

286288
def is_disconnected(self) -> bool:
287289
"""
@@ -294,12 +296,7 @@ def is_disconnected(self) -> bool:
294296
"""
295297
if self._protocol is None:
296298
return True
297-
with self._lock:
298-
try:
299-
self._protocol.disconnected.result()
300-
except (asyncio.InvalidStateError, asyncio.CancelledError, Exception):
301-
return False
302-
return True
299+
return self._protocol.disconnected.done()
303300

304301
def is_reading(self) -> bool:
305302
"""
@@ -312,8 +309,7 @@ def is_reading(self) -> bool:
312309
"""
313310
if self._transport is None:
314311
return False
315-
with self._lock:
316-
return self._transport.is_reading()
312+
return self._transport.is_reading()
317313

318314
def is_started(self) -> bool:
319315
"""
@@ -326,8 +322,7 @@ def is_started(self) -> bool:
326322
"""
327323
if self._protocol is None:
328324
return False
329-
with self._lock:
330-
return self._protocol.started.is_set()
325+
return self._protocol.started.is_set()
331326

332327
@property
333328
def metadata(self) -> Optional[databento_dbn.Metadata]:
@@ -356,9 +351,8 @@ def abort(self) -> None:
356351
"""
357352
if self._transport is None:
358353
return
359-
with self._lock:
360-
self._transport.abort()
361-
self._protocol = None
354+
self._transport.abort()
355+
self._protocol = None
362356

363357
def close(self) -> None:
364358
"""
@@ -367,10 +361,9 @@ def close(self) -> None:
367361
"""
368362
if self._transport is None:
369363
return
370-
with self._lock:
371-
if self._transport.can_write_eof():
372-
self._transport.write_eof()
373-
self._transport.close()
364+
if self._transport.can_write_eof():
365+
self._loop.call_soon_threadsafe(self._transport.write_eof)
366+
self._loop.call_soon_threadsafe(self._transport.close)
374367

375368
def subscribe(
376369
self,
@@ -421,8 +414,7 @@ def resume_reading(self) -> None:
421414
"""
422415
if self._transport is None:
423416
return
424-
with self._lock:
425-
self._transport.resume_reading()
417+
self._loop.call_soon_threadsafe(self._transport.resume_reading)
426418

427419
def start(self) -> None:
428420
"""
@@ -445,10 +437,16 @@ async def wait_for_close(self) -> None:
445437
"""
446438
if self._protocol is None:
447439
return
440+
448441
await self._protocol.disconnected
442+
disconnect_exc = self._protocol.disconnected.exception()
443+
449444
await self._protocol.wait_for_processing()
450445
self._protocol = self._transport = None
451446

447+
if disconnect_exc is not None:
448+
raise BentoError(disconnect_exc)
449+
452450
def _connect(
453451
self,
454452
dataset: Union[Dataset, str],
@@ -521,6 +519,5 @@ async def _connect_task(
521519
"authentication with remote gateway completed",
522520
)
523521

524-
with self._lock:
525-
self._transport = transport
526-
self._protocol = protocol
522+
self._transport = transport
523+
self._protocol = protocol

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ requests = ">=2.24.0"
3333
zstandard = ">=0.21.0"
3434

3535
[tool.poetry.group.dev.dependencies]
36-
mypy = "1.2.0"
36+
black = "^23.3.0"
37+
mypy = "1.3.0"
3738
pytest = ">=7.3.1"
3839
pytest-asyncio = ">=0.21.0"
3940
pytest-mock = ">=3.10.0"
41+
ruff = "^0.0.270"
4042
types-requests = "^2.30.0.0"
4143

4244
[build-system]

scripts/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#! /usr/bin/env bash
1+
#!/usr/bin/env bash
22
poetry install --with=dev --no-interaction --no-root

scripts/lint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/env bash
1+
#!/usr/bin/env bash
22
echo $(mypy --version)
33
echo Running mypy...
44
poetry run mypy databento examples tests

scripts/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#! /usr/bin/env bash
1+
#!/usr/bin/env bash
22
poetry run pytest tests . $@

tests/conftest.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import string
66
from typing import AsyncGenerator, Callable, Generator, Iterable
77

8+
import databento.live
89
import pytest
910
import pytest_asyncio
1011
from databento.common.enums import Schema
@@ -154,7 +155,6 @@ def fixture_test_api_key() -> str:
154155

155156
@pytest_asyncio.fixture(name="mock_live_server")
156157
async def fixture_mock_live_server(
157-
event_loop: asyncio.AbstractEventLoop,
158158
test_api_key: str,
159159
caplog: pytest.LogCaptureFixture,
160160
unused_tcp_port: int,
@@ -168,11 +168,20 @@ async def fixture_mock_live_server(
168168
MockLiveServer
169169
170170
"""
171-
event_loop.set_debug(True)
172171
monkeypatch.setenv(
173172
name="DATABENTO_API_KEY",
174173
value=test_api_key,
175174
)
175+
monkeypatch.setattr(
176+
databento.live,
177+
"AUTH_TIMEOUT_SECONDS",
178+
1,
179+
)
180+
monkeypatch.setattr(
181+
databento.live,
182+
"CONNECT_TIMEOUT_SECONDS",
183+
1,
184+
)
176185

177186
with caplog.at_level("DEBUG"):
178187
mock_live_server = await MockLiveServer.create(

0 commit comments

Comments
 (0)