App.open only works once then fails

Asked by Shawn Robertson on 2018-03-07

Sikuli X 1.1.2 March Nightly (same effect with 1.1.1 Stable)
Windows 10 Creators Fall update with all latest patches installed

i have my automation script that has always worked. even after updating to Windows 10 Creators update it still worked but out of now here now it no longer works the same way.

at the top of my main Unit i define my App instance:

timeslip = App(os.path.join(r"C:\tssmoketest", Settings.Version, "timeslip.exe"))

then later I call it:

timeslip.open()

it works the first time which i close either with:

timeslip.close() or another method I created called TSAppClose() which is just:

def TSAppClose():
    type(Key.F4, KeyModifier.ALT)
    wait(IMG_timeslips_exit_dialog_popup, 30)
    type('y', KeyModifier.ALT)
    waitVanish(IMG_timeslips_exit_dialog_popup)
    if exists(IMG_Win10BackupCurrentDBonExit):
        type('n', KeyModifier.ALT)
        waitVanish(IMG_Win10BackupCurrentDBonExit)

either one works fine. timeslip.close() kills the process and TSAppClose() gracerfully closes my app correctly with the UI which cleans up any threads that are running which killing the main process does not.

back to my issue.

if i do this:
timeslip = App(os.path.join(r"C:\tssmoketest", Settings.Version, "timeslip.exe"))
timeslip.open()
timeslip.close()
timeslip.open()

i get:

[log] App.open [8816:Timeslip.exe]
[log] App.close [8816:Timeslip.exe]

[error] App.open failed: C:\tssmoketest\2019\timeslip.exe not found

the only way i can get around it is by doing this:

timeslip = App(os.path.join(r"C:\tssmoketest", Settings.Version, "timeslip.exe"))
timeslip.open()
timeslip.close()

timeslip = App(os.path.join(r"C:\tssmoketest", Settings.Version, "timeslip.exe"))
timeslip.open()
timeslip.close()

any idea what i have to define my app instance every time I call it instead of just being able to define it once and call it multiple times?

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2018-03-07
Last query:
2018-03-07
Last reply:
2018-03-07
RaiMan (raimund-hocke) said : #1

I will have a look at it.

ok i have to update i was incorrect in my explanation I apologize.

if i do this:

timeslip = App(os.path.join(r"C:\tssmoketest", Settings.Version, "timeslip.exe"))
timeslip.open()
timeslip.close()
timeslip.open()
timeslip.close()
timeslip.open()
timeslip.close()

it works and I get:
[log] App.open [6920:Timeslip.exe]

[log] App.close: [6920:Timeslip.exe]

[log] App.open [2812:Timeslip.exe]

[log] App.close: [2812:Timeslip.exe]

[log] App.open [8660:Timeslip.exe]

[log] App.close: [8660:Timeslip.exe]

i can no longer do this method now because we made code changes to our core EXE application and Killing the process leaves TIMESLIP.EXE running as aproecss because Threads are running in the back ground.

so that is why I had to make a new method of:
def TSAppClose():
    type(Key.F4, KeyModifier.ALT)
    wait(IMG_timeslips_exit_dialog_popup, 30)
    type('y', KeyModifier.ALT)
    waitVanish(IMG_timeslips_exit_dialog_popup)
    if exists(IMG_Win10BackupCurrentDBonExit):
        type('n', KeyModifier.ALT)
        waitVanish(IMG_Win10BackupCurrentDBonExit)

and i had to change my code in the script to this:

timeslip = App(os.path.join(r"C:\tssmoketest", Settings.Version, "timeslip.exe"))
timeslip.open()
TSAppClose()
timeslip.open()

when i do this new script code... that is when it fails and i get:

[error] App.open failed: C:\tssmoketest\2019\timeslip.exe not found so I have to changemy code to this to make it work:

timeslip = App(os.path.join(r"C:\tssmoketest", Settings.Version, "timeslip.exe"))
timeslip.open()
TSAppClose()

timeslip = App(os.path.join(r"C:\tssmoketest", Settings.Version, "timeslip.exe"))
timeslip.open()
TSAppClose()

timeslip = App(os.path.join(r"C:\tssmoketest", Settings.Version, "timeslip.exe"))
timeslip.open()
TSAppClose()

I apologize for not explaining myself properly the first time.

thank you for any advice or help

Best RaiMan (raimund-hocke) said : #3

ok, thanks for clarification.
I just started to test and found out, that the first sequence does not make problems.

In the second (changed to your own close() method) I guess, that the problem is, that the App object now is left in a state, where it thinks it is still running, but is not, since it is closed somewhere else.

Maybe it helps, if you put an
timeslip.close()
to the end of your function TSAppClose().
Should not do any harm, but might reset the state, so it opens again afterwards.

[error] App.open failed: C:\tssmoketest\2019\timeslip.exe not found
this message might be misleading, since I guess it is simply wrong and a result of the undefined state of the app object.

Nevertheless I will check, wether the implementation does not say on reopen: the app was not closed, but is not running anymore - it will now be reset and reopened.

RaiMan (raimund-hocke) said : #4

just checked:
the mentioned trick works:
- close() complains, that it did not work, but then the reopen does its job

RaiMan (raimund-hocke) said : #5

Nevertheless I will try to fix this behavior at least to more understandable error messages.

yes sir, I can confirm it does work now albeit with the complaining message:

[error] App.close [-1:Timeslip.exe (timeslip)] C:\tssmoketest\2019\timeslip.exe did not work

how4ever it does open successfully.

i will just use this work around as my solution. i don't know if this is considered a bug that warrants "fix" so I will just use this work around as my official solution. maybe one day there will be another way to handle this scenario but for now all is good. Thank you!

Thanks RaiMan, that solved my question.

RaiMan (raimund-hocke) said : #8

In version 1.1.2 the message from the App.close() will no longer be an error, but only an action log saying
[log] App.close(): .... already closed

if used as you do it.

More will not be changed, since using an App object, you have to live with the need to change its state using the designated methods.

Thank you Raiman!