duan02143 2010-05-08 15:47
浏览 31
已采纳

当http请求完成时,GUI应用程序变得无响应

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?

  • 写回答

1条回答 默认 最新

  • dqrnskni67375 2010-05-08 16:03
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?