Skip to content

Commit

Permalink
Removed output supression during SDK loading
Browse files Browse the repository at this point in the history
  • Loading branch information
ravngr committed Feb 29, 2024
1 parent 2aa8aa9 commit e68ce9a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ authors:
given-names: Mahnaz
orcid: https://orcid.org/0000-0002-3520-1553
title: "pylinkam"
version: 1.2.5
version: 1.2.6
doi: 10.5281/zenodo.6758012
date-released: 2022-06-27
2 changes: 1 addition & 1 deletion pylinkam/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
__app_name__ = 'pylinkam'
__version__ = '1.2.5'
__version__ = '1.2.6'

__author__ = 'Chris Harrison'
__credits__ = [__author__]
Expand Down
13 changes: 6 additions & 7 deletions pylinkam/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,12 @@ def _connect_common(self, comm_info: interface.CommsInfo) -> Connection:
# Apparently this is ignored internally...
comm_handle = interface.CommsHandle(0)

with util.supress_stdout():
# Capture SDK output on stdout
connection_result = self.process_message(
interface.Message.OPEN_COMMS,
('vPtr', comm_info),
('vPtr', comm_handle)
)
# Capture SDK output on stdout
connection_result = self.process_message(
interface.Message.OPEN_COMMS,
('vPtr', comm_info),
('vPtr', comm_handle)
)

if not connection_result.flags.connected:
if connection_result.flags.errorNoDeviceFound:
Expand Down
24 changes: 0 additions & 24 deletions pylinkam/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,3 @@ def add_path(path: str) -> None:
:param path: path to add to PATH
"""
os.environ['PATH'] = path + os.pathsep + os.environ['PATH']


@contextmanager
def supress_stdout(dest_path: str = os.devnull) -> typing.Generator[None, None, None]:
stdout_fileno = sys.stdout.fileno()

def _redirect_stdout(dest: typing.TextIO) -> None:
# Close original handle
sys.stdout.close()

# Duplicate handle
os.dup2(dest.fileno(), stdout_fileno)

sys.stdout = os.fdopen(stdout_fileno, 'w')

with os.fdopen(os.dup(stdout_fileno), 'w') as stdout_file:
try:
with open(dest_path, 'w') as dest_file:
_redirect_stdout(dest_file)

yield
finally:
# Restore original stdout
_redirect_stdout(stdout_file)

0 comments on commit e68ce9a

Please sign in to comment.