GUI Application becomes unresponsive while http request is being done
Posted
by JW
on Stack Overflow
See other posts from Stack Overflow
or by JW
Published on 2010-05-08T15:47:23Z
Indexed on
2010/05/08
15:58 UTC
Read the original article
Hit count: 361
I have just made my first proper little desktop GUI application that basically wraps a GUI (php-gtk) interface around a SimpleTest Web Test case to make it act as a remote testing client.
Each time the local The Web Test case runs, it sends an HTTP request to another SimpleTest case (that has an XHTML interface) sitting on my server.
The application, allows me to run one local test that collates information from multiple remote tests. It just has a 'Start Test' button, 'Stop Test' button and a setting to increase/decrease the number of remote tests conducted in each HTTP Request. Each test-run takes about an hour to complete.
The trouble is, most of the time the application is making http requests. Furthermore, whenever an HTTP Request is being made, the application's GUI is unresponsive.
I have taken to making the application wait a few seconds (iterating through the Gtk::main_iteration ) between requests in order to give the user time to re-size the window, press the Stop button, etc. But, this makes the whole test run take a lot a longer than is necessary.
<?php
require_once('simpletest/web_tester.php');
class TestRemoteTestingClient extends WebTestCase
{
function testRunIterations()
{
...
$this->assertTrue($this->get($nextUrl), 'getting from pointer:'. $this->_remoteMementoPointer);
$this->assertResponse(200, "checking response for " . $nextUrl );
$this->assertText('RemoteNodeGreen');
$this->doGtkIterationsForMinNSeconds($secs);
...
}
public function doGtkIterationsForMinNSeconds($secs)
{
$this->appendStatusMessage("Waiting " . $secs);
$start = time();
$end = $start + $secs;
while( (time() < $end) )
{
$this->appendStatusMessage("Waiting " . ($end - time()));
while(gtk::events_pending()) Gtk::main_iteration();
}
}
}
Is there a way to keep the application responsive whilst, at the same time making an HTTP request?
I am considering splitting the application into two, where:
- Test Controller Application - Acts as a settings-writer / report-reader and this writes to settings file and reads a report file.
- Test Runner Application - Acts as a settings-reader / report-writer and, for each iteration reads the settings file, Runs the test, then write a report.
So to tell it to close down - I'd:
- Press the Stop Button on the 'Test Controller Application',
- which writes to the settings file,
- which is read by the 'Test Runner Application'
- which stops, then
- writes to the report file to say it stopped
- the 'Test Controller Application' reads the report and updates the status
- and so on...
However, before I go ahead and split the application in two - I am wondering if there is any other obvious way to deal with, this issue. I suspect it is probably quite common and a well-trodden path.
Also is there an easier way to send messages between two applications?
© Stack Overflow or respective owner