Skip to content

Commit

Permalink
add timeout option (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlcibiadesCleinias authored Jul 23, 2021
1 parent fed90e1 commit 3cd459a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,6 @@ target/

# MyPy cache
.mypy_cache/

# IDE confs
.idea
11 changes: 11 additions & 0 deletions PIconnect/PI.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,18 @@
from PIconnect.PIData import PISeries, PISeriesContainer
from PIconnect.PIConsts import AuthenticationMode

from System import TimeSpan


class PIServer(object): # pylint: disable=useless-object-inheritance
"""PIServer is a connection to an OSIsoft PI Server
Args:
server (str, optional): Name of the server to connect to, defaults to None
username (str, optional): can be used only with password as well
password (str, optional): -//-
todo: domain, auth
timeout (int, optional): the maximum seconds an operation can take
.. note::
If the specified `server` is unknown a warning is thrown and the connection
Expand All @@ -85,6 +91,7 @@ def __init__(
password=None,
domain=None,
authentication_mode=AuthenticationMode.PI_USER_AUTHENTICATION,
timeout=None,
):
if server and server not in self.servers:
message = 'Server "{server}" not found, using the default server.'
Expand All @@ -108,8 +115,12 @@ def __init__(
self._credentials = (NetworkCredential(*cred), int(authentication_mode))
else:
self._credentials = None

self.connection = self.servers.get(server, self.default_server)

if timeout:
self.connection.ConnectionInfo.OperationTimeOut = TimeSpan(0, 0, timeout) # hour, min, sec

def __enter__(self):
if self._credentials:
self.connection.Connect(*self._credentials)
Expand Down

0 comments on commit 3cd459a

Please sign in to comment.