Lengthy operations block UI

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Lengthy operations block UI

Andrei Stebakov
I have written some code that has a deep nested loop of calling ZnClient>>get. 
In the loop I also execute Transcript>>show but I can only see the transcript output after a few seconds when the loop is finished. During all that time while the loop is busy the UI is also unresponsive.
Is there a way to execute code in some sort of asynchronous way?
Reply | Threaded
Open this post in threaded view
|

Re: Lengthy operations block UI

Sven Van Caekenberghe-2
Hi Andrei,

> On 25 Jan 2018, at 16:26, Andrei Stebakov <[hidden email]> wrote:
>
> I have written some code that has a deep nested loop of calling ZnClient>>get.
> In the loop I also execute Transcript>>show but I can only see the transcript output after a few seconds when the loop is finished. During all that time while the loop is busy the UI is also unresponsive.
> Is there a way to execute code in some sort of asynchronous way?

The problem is not specific to using ZnClient, it is with every loop you execute in the UI thread: the Transcript output is not updated (as it is the UI thread itself that has to do the drawing).

For example, try

  1 to: 10 do: [ :i | Transcript crShow: i. 5 seconds wait ].

The solution is to run you long running code in another thread, like this

  [ 1 to: 10 do: [ :i | Transcript crShow: i. 5 seconds wait ] ] fork.

HTH,

Sven
Reply | Threaded
Open this post in threaded view
|

Re: Lengthy operations block UI

Andrei Stebakov
Thanks, Sven, got it

On Jan 25, 2018 10:36, "Sven Van Caekenberghe" <[hidden email]> wrote:
Hi Andrei,

> On 25 Jan 2018, at 16:26, Andrei Stebakov <[hidden email]> wrote:
>
> I have written some code that has a deep nested loop of calling ZnClient>>get.
> In the loop I also execute Transcript>>show but I can only see the transcript output after a few seconds when the loop is finished. During all that time while the loop is busy the UI is also unresponsive.
> Is there a way to execute code in some sort of asynchronous way?

The problem is not specific to using ZnClient, it is with every loop you execute in the UI thread: the Transcript output is not updated (as it is the UI thread itself that has to do the drawing).

For example, try

  1 to: 10 do: [ :i | Transcript crShow: i. 5 seconds wait ].

The solution is to run you long running code in another thread, like this

  [ 1 to: 10 do: [ :i | Transcript crShow: i. 5 seconds wait ] ] fork.

HTH,

Sven
Reply | Threaded
Open this post in threaded view
|

Re: Lengthy operations block UI

Andrei Stebakov
How do you handle forked operations from TestCase point of view, when the test expects a value to assert from an asynchronous operation?

On Jan 25, 2018 10:41, "Andrei Stebakov" <[hidden email]> wrote:
Thanks, Sven, got it

On Jan 25, 2018 10:36, "Sven Van Caekenberghe" <[hidden email]> wrote:
Hi Andrei,

> On 25 Jan 2018, at 16:26, Andrei Stebakov <[hidden email]> wrote:
>
> I have written some code that has a deep nested loop of calling ZnClient>>get.
> In the loop I also execute Transcript>>show but I can only see the transcript output after a few seconds when the loop is finished. During all that time while the loop is busy the UI is also unresponsive.
> Is there a way to execute code in some sort of asynchronous way?

The problem is not specific to using ZnClient, it is with every loop you execute in the UI thread: the Transcript output is not updated (as it is the UI thread itself that has to do the drawing).

For example, try

  1 to: 10 do: [ :i | Transcript crShow: i. 5 seconds wait ].

The solution is to run you long running code in another thread, like this

  [ 1 to: 10 do: [ :i | Transcript crShow: i. 5 seconds wait ] ] fork.

HTH,

Sven
Reply | Threaded
Open this post in threaded view
|

Re: Lengthy operations block UI

Sven Van Caekenberghe-2


> On 26 Jan 2018, at 16:16, Andrei Stebakov <[hidden email]> wrote:
>
> How do you handle forked operations from TestCase point of view, when the test expects a value to assert from an asynchronous operation?

tests typically run sequential & synchronous, it is hard to work with them otherwise (to debug them, to handle there failures).

it is of course possible to write much more complex tests, doing all kind of magic, but well, they are complex and require experience.

many Zn test run http client against http servers, you could look there for examples.

what is your exact scenario or use case ?

> On Jan 25, 2018 10:41, "Andrei Stebakov" <[hidden email]> wrote:
> Thanks, Sven, got it
>
> On Jan 25, 2018 10:36, "Sven Van Caekenberghe" <[hidden email]> wrote:
> Hi Andrei,
>
> > On 25 Jan 2018, at 16:26, Andrei Stebakov <[hidden email]> wrote:
> >
> > I have written some code that has a deep nested loop of calling ZnClient>>get.
> > In the loop I also execute Transcript>>show but I can only see the transcript output after a few seconds when the loop is finished. During all that time while the loop is busy the UI is also unresponsive.
> > Is there a way to execute code in some sort of asynchronous way?
>
> The problem is not specific to using ZnClient, it is with every loop you execute in the UI thread: the Transcript output is not updated (as it is the UI thread itself that has to do the drawing).
>
> For example, try
>
>   1 to: 10 do: [ :i | Transcript crShow: i. 5 seconds wait ].
>
> The solution is to run you long running code in another thread, like this
>
>   [ 1 to: 10 do: [ :i | Transcript crShow: i. 5 seconds wait ] ] fork.
>
> HTH,
>
> Sven


Reply | Threaded
Open this post in threaded view
|

Re: Lengthy operations block UI

Andrei Stebakov
Basically the test confirms that the long lasting scraping operation returns the expected result . As you suggested let me take a look at Zn 

On Jan 26, 2018 10:31, "Sven Van Caekenberghe" <[hidden email]> wrote:


> On 26 Jan 2018, at 16:16, Andrei Stebakov <[hidden email]> wrote:
>
> How do you handle forked operations from TestCase point of view, when the test expects a value to assert from an asynchronous operation?

tests typically run sequential & synchronous, it is hard to work with them otherwise (to debug them, to handle there failures).

it is of course possible to write much more complex tests, doing all kind of magic, but well, they are complex and require experience.

many Zn test run http client against http servers, you could look there for examples.

what is your exact scenario or use case ?

> On Jan 25, 2018 10:41, "Andrei Stebakov" <[hidden email]> wrote:
> Thanks, Sven, got it
>
> On Jan 25, 2018 10:36, "Sven Van Caekenberghe" <[hidden email]> wrote:
> Hi Andrei,
>
> > On 25 Jan 2018, at 16:26, Andrei Stebakov <[hidden email]> wrote:
> >
> > I have written some code that has a deep nested loop of calling ZnClient>>get.
> > In the loop I also execute Transcript>>show but I can only see the transcript output after a few seconds when the loop is finished. During all that time while the loop is busy the UI is also unresponsive.
> > Is there a way to execute code in some sort of asynchronous way?
>
> The problem is not specific to using ZnClient, it is with every loop you execute in the UI thread: the Transcript output is not updated (as it is the UI thread itself that has to do the drawing).
>
> For example, try
>
>   1 to: 10 do: [ :i | Transcript crShow: i. 5 seconds wait ].
>
> The solution is to run you long running code in another thread, like this
>
>   [ 1 to: 10 do: [ :i | Transcript crShow: i. 5 seconds wait ] ] fork.
>
> HTH,
>
> Sven