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

logger crashes at the end of the program #37

Open
nmz787 opened this issue Mar 30, 2020 · 6 comments
Open

logger crashes at the end of the program #37

nmz787 opened this issue Mar 30, 2020 · 6 comments
Labels
bug Something isn't working

Comments

@nmz787
Copy link

nmz787 commented Mar 30, 2020

trying to set that ENV var in the script:

import os
os.environ['WEXPECT_SPAWN_CLASS'] = 'SpawnPipe'
os.environ['WEXPECT_LOGGER_LEVEL']='INFO'
from wexpect import spawn
from wexpect import TIMEOUT, EOF

yields this error at the end of my script

Traceback (most recent call last):
  File "C:\misc\my_script_dir\wexpect\host.py", line 312, in __del__
    logger.info('Deleting...')
  File "C:\Python36\lib\logging\__init__.py", line 1308, in info
    self._log(INFO, msg, args, **kwargs)
  File "C:\Python36\lib\logging\__init__.py", line 1444, in _log
    self.handle(record)
  File "C:\Python36\lib\logging\__init__.py", line 1454, in handle
    self.callHandlers(record)
  File "C:\Python36\lib\logging\__init__.py", line 1516, in callHandlers
    hdlr.handle(record)
  File "C:\Python36\lib\logging\__init__.py", line 865, in handle
    self.emit(record)
  File "C:\Python36\lib\logging\__init__.py", line 1071, in emit
    self.stream = self._open()
  File "C:\Python36\lib\logging\__init__.py", line 1061, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
NameError: name 'open' is not defined
Exception ignored in: <bound method SpawnBase.__del__ of <wexpect.host.SpawnPipe object at 0x000002444AD03E48>>
Traceback (most recent call last):
  File "C:\misc\my_script_dir\wexpect\host.py", line 320, in __del__
  File "C:\Python36\lib\logging\__init__.py", line 1320, in warning
  File "C:\Python36\lib\logging\__init__.py", line 1444, in _log
  File "C:\Python36\lib\logging\__init__.py", line 1454, in handle
  File "C:\Python36\lib\logging\__init__.py", line 1516, in callHandlers
  File "C:\Python36\lib\logging\__init__.py", line 865, in handle
  File "C:\Python36\lib\logging\__init__.py", line 1071, in emit
  File "C:\Python36\lib\logging\__init__.py", line 1061, in _open
NameError: name 'open' is not defined
@nmz787
Copy link
Author

nmz787 commented Mar 30, 2020

this looks relevant to my exception:
https://stackoverflow.com/a/29737870/253127

[that user's] code used to work until Python 3.4. I know because I've just run into the same issue, calling open() within del. Apparently built-in functions no longer work, because of a change in when del is run as the interpreter shuts down.

@raczben
Copy link
Owner

raczben commented Mar 30, 2020

I've run your snippet, with no error...

Can you describe your setup to help reporduce the issue?

@nmz787
Copy link
Author

nmz787 commented Mar 30, 2020

That snippet was just the setup, later in your test you would need to run some normal wexpect scenarios... spawning and expecting. Maybe this bug was only in the last release (v 3.3.0)?

@nmz787
Copy link
Author

nmz787 commented Mar 30, 2020

Also, are you using Python > version 3.4? I was using 3.6

@raczben
Copy link
Owner

raczben commented Mar 30, 2020

I use:

  • Win 10.0.18362 Build 18362
  • Python 3.7.5

Note, that wexpect requires Python 3.5 or higher because the Literal String Interpolation aka. Python f-Strings

I have added your snippet at the beginning of the hello_wexpect example which results the following code, but it still run with no errors.

I cannot reproduce your problem. Can you help me?

'''
This is the simplest example. It starts a windows command interpreter (aka. cmd) lists the current
directory and exits.
'''
import os
os.environ['WEXPECT_SPAWN_CLASS'] = 'SpawnPipe'
os.environ['WEXPECT_LOGGER_LEVEL']='INFO'
from wexpect import spawn
from wexpect import TIMEOUT, EOF


# Start cmd as child process
child = spawn('cmd.exe')

# Wait for prompt when cmd becomes ready.
child.expect('>')

# Prints the cmd's start message
print(child.before, end='')
print(child.after, end='')

# run list directory command
child.sendline('ls')

# Waiting for prompt
child.expect('>')

# Prints content of the directory
print(child.before, end='')
print(child.after, end='')

# Exit from cmd
child.sendline('exit')

# Waiting for cmd termination.
child.wait()

@raczben raczben added the bug Something isn't working label Mar 30, 2020
@nmz787
Copy link
Author

nmz787 commented Jul 2, 2020

ok, this issue is a result of me having a class in the file... it doesn't seem to matter where it's defined, before or after imports, before or after the wexpect usage or wait

'''
This is the simplest example. It starts a windows command interpreter (aka. cmd) lists the current
directory and exits.
'''

class a_class():
    def __init__(self):
        pass


import os
os.environ['WEXPECT_SPAWN_CLASS'] = 'SpawnPipe'
os.environ['WEXPECT_LOGGER_LEVEL']='INFO'
from wexpect import spawn
from wexpect import TIMEOUT, EOF


# Start cmd as child process
child = spawn('cmd.exe')

# Wait for prompt when cmd becomes ready.
child.expect('>')

# Prints the cmd's start message
print(child.before, end='')
print(child.after, end='')

# run list directory command
child.sendline('ls')

# Waiting for prompt
child.expect('>')

# Prints content of the directory
print(child.before, end='')
print(child.after, end='')

# Exit from cmd
child.sendline('exit')

# Waiting for cmd termination.
child.wait()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants