pyvisa / pyvisa-py

A pure python PyVISA backend

Home Page:https://pyvisa-py.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Calling open_resource with a hislip address when the instrument is not available causes hang (works ok using Keysight backend)

DareDevilDenis opened this issue · comments

The code below attempts to connect to a non-existent hislip instrument "hislip999" on the local machine. The call to 'open_resource' hangs.

To Reproduce

import pyvisa

rm = pyvisa.ResourceManager("@py")   # If I remove "@py" then it works i.e. the connection attempt immediately fails
my_instrument = rm.open_resource("TCPIP0::127.0.0.1::hislip999::INSTR")

If I remove "@py" so that it uses my installation of Keysight IVI backend then it works as expected - we get immediate exception pyvisa.errors.VisaIOError: VI_ERROR_RSRC_NFOUND (-1073807343): Insufficient location information or the requested device or resource is not present in the system

Output of pyvisa-info

Machine Details:
   Platform ID:    Windows-10-10.0.19045-SP0
   Processor:      Intel64 Family 6 Model 141 Stepping 1, GenuineIntel

Python:
   Implementation: CPython
   Executable:     C:\Program Files\Python312\python.exe
   Version:        3.12.0
   Compiler:       MSC v.1935 64 bit (AMD64)
   Architecture:   AMD64
   Build:          Oct  2 2023 13:03:39 (#tags/v3.12.0:0fb18b0)
   Unicode:        UCS4

PyVISA Version: 1.14.1

Backends:
   ivi:
      Version: 1.14.1 (bundled with PyVISA)
      #1: C:\Windows\system32\visa32.dll:
         found by: auto
         architecture:
            ('x86', 64)
         Vendor: Keysight Technologies
         Impl. Version: 1377199637
         Spec. Version: 5244928
      #2: C:\Windows\system32\visa64.dll:
         found by: auto
         architecture:
            ('x86', 64)
         Vendor: Keysight Technologies
         Impl. Version: 1377199637
         Spec. Version: 5244928
   py:
      Version: 0.7.2
      TCPIP INSTR: Available
         Resource discovery:
         - VXI-11: partial (psutil not installed)
         - hislip: disabled (zeroconf not installed)
      TCPIP SOCKET: Available
      ASRL INSTR:
         Please install PySerial (>=3.0) to use this resource type.
         No module named 'serial'
      USB INSTR:
         Please install PyUSB to use this resource type.
         No module named 'usb'
      USB RAW:
         Please install PyUSB to use this resource type.
         No module named 'usb'
      VICP INSTR:
         Please install PyVICP to use this resource type.
      GPIB INSTR:
         Please install linux-gpib (Linux) or gpib-ctypes (Windows, Linux) to use this resource type. Note that installing gpib-ctypes will give you access to a broader range of functionalities.
         No module named 'gpib'
      GPIB INTFC:
         Please install linux-gpib (Linux) or gpib-ctypes (Windows, Linux) to use this resource type. Note that installing gpib-ctypes will give you access to a broader range of functionalities.
         No module named 'gpib'

Indeed hslip currently ignore the open_timeout. Please have a look at #430

Hi @MatthieuDartiailh
I don't have enough knowledge of pyvisa-py to be able to review your PR however I tried your fix by installing it as follows:

pip install git+https://github.com/pyvisa/pyvisa-py@hislip-connect-timeout

I repeated the above test, trying to connect to a non-existent hislip instrument ("hislip999") and it threw the following exception:

Traceback (most recent call last):
  File "C:\temp\test_timeout.py", line 4, in <module>
    my_instrument = rm.open_resource("TCPIP0::127.0.0.1::hislip999::INSTR")
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\pyvisa\highlevel.py", line 3292, in open_resource
    res.open(access_mode, open_timeout)
  File "C:\Program Files\Python312\Lib\site-packages\pyvisa\resources\resource.py", line 281, in open
    self.session, status = self._resource_manager.open_bare_resource(
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\pyvisa\highlevel.py", line 3217, in open_bare_resource
    return self.visalib.open(self.session, resource_name, access_mode, open_timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\pyvisa_py\highlevel.py", line 168, in open
    sess = cls(session, resource_name, parsed, open_timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\pyvisa_py\tcpip.py", line 86, in __new__
    return newcls(resource_manager_session, resource_name, parsed, open_timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\pyvisa_py\sessions.py", line 322, in __init__
    self.after_parsing()
  File "C:\Program Files\Python312\Lib\site-packages\pyvisa_py\tcpip.py", line 138, in after_parsing
    self.interface = hislip.Instrument(
                     ^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\pyvisa_py\protocols\hislip.py", line 386, in __init__
    self._sync.connect((ip_addr, port))
BlockingIOError: [WinError 10035] A non-blocking socket operation could not be completed immediately

I initially thought that this was the expected result however when I repeated the test with an available instrument it threw the same exception.

commented

Hi @MatthieuDartiailh, did I run it correctly?

Sorry I have been quite busy lately with little time for OSS. I will try to look into it this week.