Skip to content
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

multiple instances of ResourceMaganer #68

Closed
yn4k4nishi opened this issue Dec 15, 2022 · 7 comments
Closed

multiple instances of ResourceMaganer #68

yn4k4nishi opened this issue Dec 15, 2022 · 7 comments

Comments

@yn4k4nishi
Copy link

when I create multiple instance of ResourceManager, dialogue response is wrong.
Is it not recommended?

my environment:

  • python 3.8.10
  • PyVISA 1.11.3
  • PyVISA-py 0.5.2
  • PyVISA-sim 0.4.0
@MatthieuDartiailh
Copy link
Member

Could you provide a sample script illustrating your issue ?

@bilderbuchi
Copy link

Not sure what @yn4k4nishi means, but I also observe weird problems running pytest tests with pyvisa-sim backed fixture objects, in that replies remain in a read buffer despite the objects + resource managers being destroyed:

>>> import pyvisa
>>> rm = pyvisa.ResourceManager(visa_library='@sim')
>>> instr = rm.open_resource('ASRL2::INSTR')
>>> instr.write('*IDN?')
7
>>> instr.read()
'SCPI,MOCK,VERSION_1.0\n'  # OK, that's what I expect
>>> instr.write('*IDN?')  # we don't fetch that response from the instrument
7
>>> id(instr)
140011221241280
>>> del instr  # Kill the instrument
>>> del rm
>>> rm = pyvisa.ResourceManager(visa_library='@sim')
>>> instr = rm.open_resource('ASRL2::INSTR')
>>> instr.read()  # Why is this response in this different instrument object?
'SCPI,MOCK,VERSION_1.0\n'
>>> id(instr)
140011221241472  # the IDs of the instr objects are different, so it's not somehow the same

Is that expected?

@MatthieuDartiailh
Copy link
Member

Here you are assuming that when you delete the instr and the resource manager they instantaneously go away. This may not be true because the rm and the library object are in a reference cycle and the gc may dispose of them only later on. Could you run the same code but explicitly closing the instr and rm rather than relying on __del__ being invoked.

@bilderbuchi
Copy link

bilderbuchi commented Jan 25, 2023

Ah, you are right. instr.close() is neither sufficient nor necessary, rm.close() does the trick. Thanks!
Argh, Python's behaviour around __del__ is annoying at times. 😠

@MatthieuDartiailh
Copy link
Member

The fact that closing the instrument does not solve the issue still says that something is off. Instruments do not share outgoing buffers between connections and we should mimic that.

@bilderbuchi
Copy link

The fact that closing the instrument does not solve the issue still says that something is off. Instruments do not share outgoing buffers between connections and we should mimic that.

@MatthieuDartiailh is that something that still should be followed up separately? (to avoid this disappearing in a closed issue comment)

@MatthieuDartiailh
Copy link
Member

It would make sense yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants