Skip to content

Commit df6126d

Browse files
authored
Merge pull request #22 from rambo/tcp_eventloop_fix
Fix eventloop issues with TCPTransport
2 parents fa2a8db + c24cb7f commit df6126d

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 2.5.0
2+
current_version = 2.5.1
33
commit = False
44
tag = False
55

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "scpi"
3-
version = "2.5.0"
3+
version = "2.5.1"
44
description = "Basic idea here is to make transport-independent command sender/parser and a device baseclass that implements the common SCPI commands"
55
authors = ["Eero af Heurlin <eero.afheurlin@iki.fi>"]
66
homepage = "https://github.com/rambo/python-scpi/"

src/scpi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""SCPI module, the scpi class implements the base command set, devices may extend it.
22
transports are separate from devices (so you can use for example hp6632b with either serial port or GPIB)"""
33

4-
__version__ = "2.5.0" # NOTE Use `bump2version --config-file patch` to bump versions correctly
4+
__version__ = "2.5.1" # NOTE Use `bump2version --config-file patch` to bump versions correctly
55
from .scpi import SCPIProtocol, SCPIDevice
66
from .errors import CommandError
77

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:

tests/test_scpi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
def test_version() -> None:
77
"""Make sure version matches expected"""
8-
assert __version__ == "2.5.0"
8+
assert __version__ == "2.5.1"

0 commit comments

Comments
 (0)