Sikuli IDE not reappearing after script execution

Asked by Test

Hey there,

I have a script in the Sikuli IDE that, upon completion, does not bring the IDE back up. I'm running on Windows 8.

Basically, after my script runs, the IDE does not reappear but the command prompt window remains open, and I receive no errors whatsoever.

This started after I began using a logger with python.

import logging
logger = logging.getLogger('myapp')
hdlr = logging.FileHandler(logFile)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s', '%Y-%m-%d %H:%M:%S')
hdlr.setFormatter(formatter)
hdlr.setLevel(logging.INFO)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)

I then have multiple instances of the following:

logger.info('Test complete')
logger.info('Step x complete')

The logFile name is different each time as it relies on the timestamp.

Apart from logger.info() I don't deal with the logger anywhere else in my script. Do I need to do something like logger.shutdown(), or something like that?

Sometimes when the IDE does reappear, I get this message:

Traceback (most recent call last):
File "C:\path-to-sikuli\Sikuli\sikuli-ide.jar\Lib\logging\__init__.py", line 750, in emit
File "C:\path-to-sikuli\Sikuli\sikuli-ide.jar\Lib\logging\__init__.py", line 750, in emit
ValueError: I/O operation on closed file

I'm not very well versed with the logging process in Python so apologies in advance if it's a basic mistake I'm making.

Thanks.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

you have to shutdown the logger explicitly before terminating the script.

Revision history for this message
Test (c4456517) said :
#2

So I should do logger.shutdown() just before exit()?

Revision history for this message
RaiMan (raimund-hocke) said :
#3

yes.

tried it?

Revision history for this message
Test (c4456517) said :
#4

Traceback (most recent call last):
File "C:\path-to-sikuli\Sikuli\sikuli-ide.jar\Lib\logging\__init__.py", line 750, in emit
File "C:\path-to-sikuli\Sikuli\sikuli-ide.jar\Lib\logging\__init__.py", line 750, in emit
ValueError: I/O operation on closed file

[error] script [ myScript ] stopped with error in line 91
[error] AttributeError ( Logger instance has no attribute 'shutdown' )

Pretty much the exact error as before.

Revision history for this message
Test (c4456517) said :
#6

When the user inputs Q to quit the script or when my script runs to completion, this is found at the end:

logger.shutdown()
exit()

Yet I got those same errors.

Revision history for this message
Test (c4456517) said :
#7

To add on a bit more info, the Sikuli IDE now DOES reappear after about 5 seconds, quite a long delay, after the script should've stopped, and gives me all those messages.

Revision history for this message
Best RaiMan (raimund-hocke) said :
#8

try
logging.shutdown()

Revision history for this message
RaiMan (raimund-hocke) said :
#9

Another thing:
Why are you using handlers?

Isn't basic logging enough?

look:
http://docs.python.org/2/howto/logging.html#basic-logging-tutorial

Revision history for this message
Test (c4456517) said :
#10

Thanks RaiMan, that solved my question.

Revision history for this message
Test (c4456517) said :
#11

I'll need to read up more about it because I just followed a tutorial to start off.

Thanks for all the help, you have no idea how grateful I am.