-
-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
opening TCP/IP connection to invalid IP blocks forever #88
Comments
Different approach implemented in TCPIP INSTR and TPCIP SOCKET.
None is correct, handling of connect timeout is not provided. In SOCKET mode, also there is no check, if connect was succesful. |
115: TCPIP SOCKET improvements r=skrchnavy a=skrchnavy * Connect uses open_timeout parameter to be timeouted (#88) * Refactored read operation with improved timeout handling * Read Uses bytearray and bytes instead of string - inspired by #50 * Calculation of return data in read uses indexes * Renamed some variables for better readability.
@skrchnavy Uhm, I'm not sure. What's the difference? I'm sending GPIB commands to the device via TCP, so its INSTR? |
@iliis : There are 2 types of devices:
Device shall not block in case, when timeout != Anyway I have INSTR changes in progress. Do you have access to a device for testing? |
120: TCPIP INSTR Session / RPC timeout handling improvements r=MatthieuDartiailh a=skrchnavy * `rpc` module changes: * updated to use timeout and fragmentation size in recv and write operations * fragmentation support in write operation * connect is timeouted based on timeout * 'select' moved to `_sendrecord` and `_recvrecord` functions * `tcpip` module: * open_timeout passed to rpc via vxi11 Related to #88
While
resource_manager.open_resource('TCPIP::127.0.0.1')
immediately raises aConnectionRefusedError
, connecting to an IP that doesn't exist (e.g. doingresource_manager.open_resource('TCPIP::192.255.255.42')
or something) will block forever.This is an issue in https://github.com/hgrecco/pyvisa-py/blob/master/pyvisa-py/protocols/rpc.py#L339:
socket.connect()
blocks as the socket is in blocking mode. Adding for examplesocket.settimeout(5)
immediately before this puts the socket into timeout mode and theconnect()
will timeout after five seconds.I haven't checked, but as long as the socket is in blocking mode other operations might behave similarly and block forever (or timeout after a very long time).
I would suggest to at least set some default timeout. Pyvisa actually has a parameter for that in
open_resource()
calledopen_timeout
(see http://pyvisa.readthedocs.io/en/stable/api/resourcemanager.html#pyvisa.highlevel.ResourceManager.open_resource).See also https://docs.python.org/3/library/socket.html#socket-timeouts
The text was updated successfully, but these errors were encountered: