avocado-framework / aexpect

Python library used to control interactive programs
GNU General Public License v2.0
8 stars 32 forks source link

Error "name 'open' is not defined" during `Spawn` deletion #122

Closed pevogam closed 10 months ago

pevogam commented 1 year ago

This is an odd issue since open must be replaced or somehow modified but during deletion of a Spawn instance I keep getting

2023-03-28 13:29:26,733 aexpect.remote_door INFO | Exception ignored in: <function Spawn.__del__ at 0x7f2fac19d120>
2023-03-28 13:29:26,733 aexpect.remote_door INFO | Traceback (most recent call last):
2023-03-28 13:29:26,733 aexpect.remote_door INFO |   File "/usr/lib/python3.10/site-packages/aexpect/client.py", line 236, in __del__
2023-03-28 13:29:26,733 aexpect.remote_door INFO |   File "/usr/lib/python3.10/site-packages/aexpect/client.py", line 389, in close
2023-03-28 13:29:26,733 aexpect.remote_door INFO |   File "/usr/lib/python3.10/site-packages/aexpect/client.py", line 380, in kill
2023-03-28 13:29:26,734 aexpect.remote_door INFO |   File "/usr/lib/python3.10/site-packages/aexpect/client.py", line 319, in get_pid
2023-03-28 13:29:26,734 aexpect.remote_door INFO | NameError: name 'open' is not defined

I haven't seen this problem before so it might be recent, not sure if anyone else has seen this.

ldoktor commented 1 year ago

Do you have a simple reproducer for this issue? I remember similar issues on cleanup in another project when the process was interrupted and gc was already cleaning the objects that were in the process of manual __del__ execution (and were incomplete)

pevogam commented 1 year ago

I think the reason is in not closing the sessions manually and using a _session_cache class attribute, then ending the script. I would have expected that the default __del__ of the sessions would properly close them but perhaps I am wrong and using close() explicitly is actually needed. What would solve the problem on my side is if I added this (ignore the private access for illustration purposes) to the end of the python script:

for session in pool.TransferOps._session_cache.values():
    session.close()

in order to purge the cache of sessions and close each previously created one.

pevogam commented 10 months ago

Since this problem no longer appears in any of my use I am closing this. Perhaps what we have documented so far might be useful if we encounter anything similar in the future.