VI_ERROR_RSRC_BUSY (-1073807246): The resource is valid, but VISA cannot currently access it

Hi

I am trying to establish a serial communication with VISA on windows 10, python 3.7.3 :

import visa

rm = visa.ResourceManager()
instr = rm.open_resource('ASRL1::INSTR')

app = dash.Dash(__name__)
server = app.server
app.scripts.config.serve_locally = True
app.config["suppress_callback_exceptions"] = True

if __name__ == '__main__':
    app.run_server(port=8800, debug=True)

but get the following error when it’s trying to open the resource.

pyvisa.errors.VisaIOError: VI_ERROR_RSRC_BUSY (-1073807246): The resource is valid, but VISA cannot currently access it.

NI IO Trace Output:

2019-05-15 08:14:27,623 - pyvisa - DEBUG - No visa library specified, trying to find alternatives.
2019-05-15 08:14:27,623 - pyvisa - DEBUG - Environment variable PYVISA_LIBRARY is unset.
2019-05-15 08:14:27,627 - pyvisa - DEBUG - No user defined library files
2019-05-15 08:14:27,632 - pyvisa - DEBUG - Automatically found library files: ['C:\\WINDOWS\\system32\\visa64.dll', 'C:\\WINDOWS\\system32\\visa32.dll']
2019-05-15 08:14:27,632 - pyvisa - DEBUG - The NI implementation available
2019-05-15 08:14:27,633 - pyvisa - DEBUG - No user defined library files
2019-05-15 08:14:27,638 - pyvisa - DEBUG - Automatically found library files: ['C:\\WINDOWS\\system32\\visa64.dll', 'C:\\WINDOWS\\system32\\visa32.dll']
2019-05-15 08:14:27,641 - pyvisa - DEBUG - Library signatures: 90 ok, 0 failed
2019-05-15 08:14:27,641 - pyvisa - DEBUG - Created library wrapper for C:\WINDOWS\system32\visa64.dll
2019-05-15 08:14:27,663 - pyvisa - DEBUG - viOpenDefaultRM('<ViObject object at 0x000001EF536EC748>',) -> 0
2019-05-15 08:14:27,663 - pyvisa - DEBUG - Created ResourceManager with session 4097
2019-05-15 08:14:27,664 - pyvisa - DEBUG - viParseRsrcEx(4097, 'ASRL1::INSTR', 'c_ushort(4)', 'c_ushort(1)', <ctypes.c_char_Array_256 object at 0x000001EF536EC8C8>, <ctypes.c_char_Array_256 object at 0x000001EF536EC9C8>, <ctypes.c_char_Array_256 object at 0x000001EF536ECA48>) -> 0
2019-05-15 08:14:27,664 - pyvisa - DEBUG - ASRL1::INSTR - opening ...
2019-05-15 08:14:27,665 - pyvisa - DEBUG - viOpen(4097, 'ASRL1::INSTR', <AccessModes.no_lock: 0>, 0, '<ViObject object at 0x000001EF536ECA48>') -> -1073807246
Traceback (most recent call last):
  File "C:\Users\labuser\Documents\pyControl\codes\test.py", line 6, in <module>
    instr = rm.open_resource('ASRL1::INSTR')
  File "C:\Users\labuser\Anaconda3\envs\controller\lib\site-packages\pyvisa\highlevel.py", line 1724, in open_resource
    res.open(access_mode, open_timeout)
  File "C:\Users\labuser\Anaconda3\envs\controller\lib\site-packages\pyvisa\resources\resource.py", line 209, in open
    self.session, status = self._resource_manager.open_bare_resource(self._resource_name, access_mode, open_timeout)
  File "C:\Users\labuser\Anaconda3\envs\controller\lib\site-packages\pyvisa\highlevel.py", line 1681, in open_bare_resource
    return self.visalib.open(self.session, resource_name, access_mode, open_timeout)
  File "C:\Users\labuser\Anaconda3\envs\controller\lib\site-packages\pyvisa\ctwrapper\functions.py", line 1213, in open
    ret = library.viOpen(session, resource_name, access_mode, open_timeout, byref(out_session))
  File "C:\Users\labuser\Anaconda3\envs\controller\lib\site-packages\pyvisa\ctwrapper\highlevel.py", line 188, in _return_handler
    raise errors.VisaIOError(ret_value)
pyvisa.errors.VisaIOError: VI_ERROR_RSRC_BUSY (-1073807246): The resource is valid, but VISA cannot currently access it.
2019-05-15 08:14:27,707 - pyvisa - DEBUG - ASRL1::INSTR - closing
2019-05-15 08:14:27,987 - pyvisa - DEBUG - ASRL1::INSTR - closing
2019-05-15 08:14:27,988 - pyvisa - DEBUG - viDisableEvent(1, 1073709055, 65535) -> 1073676291
2019-05-15 08:14:27,988 - pyvisa - DEBUG - viDiscardEvents(1, 1073709055, 65535) -> 1073676292
2019-05-15 08:14:27,999 - pyvisa - DEBUG - viClose(1,) -> 0
2019-05-15 08:14:27,999 - pyvisa - DEBUG - ASRL1::INSTR - is closed

Running this code independent of dash daq server works fine:

import visa
visa.log_to_screen()
rm = visa.ResourceManager()

instr = rm.open_resource('COM1')

NI IO Trace Output:

2019-05-15 08:16:41,291 - pyvisa - DEBUG - No visa library specified, trying to find alternatives.
2019-05-15 08:16:41,291 - pyvisa - DEBUG - Environment variable PYVISA_LIBRARY is unset.
2019-05-15 08:16:41,291 - pyvisa - DEBUG - No user defined library files
2019-05-15 08:16:41,301 - pyvisa - DEBUG - Automatically found library files: ['C:\\WINDOWS\\system32\\visa64.dll', 'C:\\WINDOWS\\system32\\visa32.dll']
2019-05-15 08:16:41,301 - pyvisa - DEBUG - The NI implementation available
2019-05-15 08:16:41,301 - pyvisa - DEBUG - No user defined library files
2019-05-15 08:16:41,301 - pyvisa - DEBUG - Automatically found library files: ['C:\\WINDOWS\\system32\\visa64.dll', 'C:\\WINDOWS\\system32\\visa32.dll']
2019-05-15 08:16:41,311 - pyvisa - DEBUG - Library signatures: 90 ok, 0 failed
2019-05-15 08:16:41,311 - pyvisa - DEBUG - Created library wrapper for C:\WINDOWS\system32\visa64.dll
2019-05-15 08:16:41,331 - pyvisa - DEBUG - viOpenDefaultRM('<ViObject object at 0x000001BA96BC35C8>',) -> 0
2019-05-15 08:16:41,331 - pyvisa - DEBUG - Created ResourceManager with session 4097
2019-05-15 08:16:41,331 - pyvisa - DEBUG - viParseRsrcEx(4097, 'COM1', 'c_ushort(4)', 'c_ushort(1)', <ctypes.c_char_Array_256 object at 0x000001BA96BC3748>, <ctypes.c_char_Array_256 object at 0x000001BA96BC3848>, <ctypes.c_char_Array_256 object at 0x000001BA96BC38C8>) -> 0
2019-05-15 08:16:41,331 - pyvisa - DEBUG - COM1 - opening ...
2019-05-15 08:16:41,331 - pyvisa - DEBUG - viOpen(4097, 'COM1', <AccessModes.no_lock: 0>, 0, '<ViObject object at 0x000001BA96BC38C8>') -> 0
2019-05-15 08:16:41,331 - pyvisa - DEBUG - COM1 - is open with session 1
2019-05-15 08:16:41,341 - pyvisa - DEBUG - COM1 - closing
2019-05-15 08:16:41,341 - pyvisa - DEBUG - viDisableEvent(1, 1073709055, 65535) -> 1073676291
2019-05-15 08:16:41,341 - pyvisa - DEBUG - viDiscardEvents(1, 1073709055, 65535) -> 1073676292
2019-05-15 08:16:41,361 - pyvisa - DEBUG - viClose(1,) -> 0
2019-05-15 08:16:41,361 - pyvisa - DEBUG - COM1 - is closed
2019-05-15 08:16:41,361 - pyvisa - DEBUG - Closing ResourceManager (session: 4097)
2019-05-15 08:16:41,361 - pyvisa - DEBUG - viClose(4097,) -> 0

Please advise.

Cheers, Hud