Region.observe: want to pause other actions (e.g. main script) while handling event

Asked by Josh

I am using Sikuli for test automation purposes and I am trying to use Region.observe(background=True) to create a dialog handler registry. The purpose of this registry is you can define how you want certain unexpected dialogs to be handled that happen to show up during a test (eg. Windows/Flash upgrade dialogs, Crashes). Some times these dialogs are non-critical and other times they should fail the test.

This is timeline I see of what is happening:
----
1) Main Thread started
2) Register dialog (Minimize console windows) -> Region.onAppear() -> Region.observe() -> Thread A Created
3) Register dialog (Close windows upgrade request) -> Region.onAppear() -> Region.observe() -> Thread B Created
4) Start application under test
5) Perform actions
6) Windows Upgrade dialog appears -> Call handler using Thread B (sikuli)
 a) Pause main thread while handling dialog
 b) handle the dialog (close window, whatever)
 c) Resume main thread
 d) Return from handler
7) continue with test

Between step 6-7 we need to pause the main thread so that we can handle any dialogs that might mess up our test.

I am encounter a problem though.. if I pause the main thread and then inside thread B start calling any sikuli functions it seems to be hanging intermittently.. Which leads me to believe that threadB is dependant on the MainThread some how ..

I am not sure a useful purpose of a background observer if the main program execution cannot be stopped one the handler is called..?

Question information

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

--- Jython or Java?

--- if I pause the main thread
How do you do that?

Could you send me your coding (at least the part showing the observe handling) https://launchpad.net/~raimund-hocke

Revision history for this message
Josh (sammysnake) said :
#2

Jython

Using Java methods for threads, didn't see any pause functionality native to python.

Handler code:
http://pastebin.com/mTXVhabJ

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

Interesting solution. I always thought about something like this for parallel observations.

I will have a deeper look into your concept together with Sikuli.

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

I have made some tests with your solution and confirm, that when the main thread is suspended while it is processing a find operation or some Java AWT Robot actions (e.g. mouse movements), the handler will hang when trying to process a Sikuli feature like find or mouse actions.

This means that internally some "locking" is used, to allow the parallel activities of main script and observe handlers during normal operation ( I did not look deeper into the code yet ).

So if the main thread or any other handler is suspended during this locked state, you have this deadlock situation.

Conclusion: Since it seems not possible (or at least without significant effort by implementing some "transaction processing") to avoid these situations, your solution is not compatible with the current implementation of the background observe.

I think it is worth, to change this question into a request bug

Revision history for this message
LiuJingnan (jingnanliu) said :
#5

I am just encounter the same problem, I want to pause the main thread's execution when specified dialog is appeared. Also I am not familiar with Java, is there any way to implement this with sikuli? Thanks :)

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

@ Liu
Since even on the Java level it is not possible, you have no chance on the Jython level (Sikuli Script) with the current implementation.

Can you help with this problem?

Provide an answer of your own, or ask Josh for more information if necessary.

To post a message you must log in.