完成 http 请求时 GUI 应用程序变得无响应
我刚刚制作了第一个合适的小型桌面 GUI 应用程序,它基本上将 GUI (php-gtk) 界面包装在 SimpleTest Web 测试用例周围,使其充当远程测试客户端。
每次本地 Web 测试用例运行时,它都会向位于我的服务器上的另一个 SimpleTest 用例(具有 XHTML 界面)发送 HTTP 请求。
该应用程序允许我运行一个本地测试,该测试可以整理来自多个远程测试的信息。它只有一个“开始测试”按钮、“停止测试”按钮以及一个用于增加/减少每个 HTTP 请求中进行的远程测试数量的设置。每次测试运行大约需要一个小时才能完成。
问题是,大多数时候应用程序都在发出 http 请求。此外,每当发出 HTTP 请求时,应用程序的 GUI 都会无响应。
我已经开始让应用程序在请求之间等待几秒钟(迭代 Gtk::main_iteration ),以便让用户有时间重新调整窗口大小、按“停止”按钮等。但是,这使得整个测试运行时间比必要的要长得多。
<?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();
}
}
}
有没有办法让应用程序在发出 HTTP 请求的同时保持响应?
我正在考虑将应用程序分成两个,其中:
- 测试控制器应用程序 - 充当设置写入器/报告读取器,这会写入设置文件并读取报告文件。
- 测试运行应用程序 - 充当设置读取器/报告编写器,并且对于每次迭代读取设置文件,运行测试,然后编写报告。
因此,要告诉它关闭 - 我会:
- 按“测试控制器应用程序”上的停止按钮,
- 该按钮将写入设置文件,
- 该文件由停止的“测试运行应用程序”读取
- ,然后
- 写入报告文件说它停止了
- “测试控制器应用程序”读取报告并更新状态
- 等等...
但是,在我继续将应用程序分成两部分之前 - 我想知道是否有任何其他明显的方法可以处理,这个问题。我怀疑这可能是很常见并且经常被人走过的道路。
还有一种更简单的方法可以在同一台计算机上的两个应用程序之间发送消息吗?
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 that sit on the same machine?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将必须实现一些线程才能同时管理多个进程。这样,当您在后台执行其他一些任务时,您的应用程序就不会变得无响应。
You will have to implement some threading in order to manage multiple processes simultanously. That way, your app wont get unresponsive while you execute some other tasks in the background.