Skip to content

Commit c24cb7f

Browse files
committed
the run_until_complete thing messes everything up when using this transport in existing asyncio loop
1 parent 56fcb53 commit c24cb7f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/scpi/transports/tcp.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ def __post_init__(self) -> None:
3131
"""Call open_connection in an eventloop"""
3232
if self.ipaddr is None or self.port is None:
3333
raise ValueError("ipaddr and port must be given")
34-
loop = asyncio.get_event_loop()
35-
loop.run_until_complete(self.open_connection(self.ipaddr, self.port))
3634

3735
async def send_command(self, command: str) -> None:
3836
"""Write command to the stream"""
37+
if not self.writer:
38+
assert self.ipaddr
39+
assert self.port
40+
await self.open_connection(self.ipaddr, self.port)
3941
if not self.writer:
4042
raise RuntimeError("Writer not set")
4143
async with self.lock:
@@ -46,6 +48,10 @@ async def send_command(self, command: str) -> None:
4648

4749
async def get_response(self) -> str:
4850
"""Get response from the stream"""
51+
if not self.reader:
52+
assert self.ipaddr
53+
assert self.port
54+
await self.open_connection(self.ipaddr, self.port)
4955
if not self.reader:
5056
raise RuntimeError("Reader not set")
5157
async with self.lock:

0 commit comments

Comments
 (0)