Async block randomly doesn't call method

Hello,

We have a method that goes through a list, we take a 50 entries from that list and go through the entries, we delete the entries from the original list when done processing. We then check if the main list is empty or not. If the main list is not empty, we call the method again with an async block. We do this until the main list is empty.

We do this to prevent time outs as we are working with a lot of entries in the list.

The problem now is, sometimes it just randomly doesn’t call the method.
As you can see here, the method ran once

you can see the prints from the first screenshot.
image

But it doesn’t call the method again.

Any help is greatly appreciated. Thank you so much :slight_smile:

hello @DALDE_John

on the following screenshot

at the bottom of the picture, there is one more print command, that is cuted, so this print does not appear in the log message?

Hi @DALDE_John

When you run Async Code it runs asynchronously blocks inside and when the main thread (process) ends it kills the worker without waiting for the Async Code invocations,
therefore there is no guarantee it complete all async code when the main thread is done.

Regards,
Vlad

@vladimir-upirov
Yes that is the goal. To call another instance of the method while the worker ends. The problem is the other instance does not seem to run.

@sergey.kuk
I think the print you are referring to is on the else statement. So no it does not appear

why do you think it does not run the method?
in the current log, you can see only logs from the current invocation and for the next execution there should be a new thread with its id

try to add a print block right before the BG_21_… method

Normally, it invokes the method 4 times in different intances. The 1st invocation,which is the one in the logs of the screenshot, runs fine but for some reason there are times that it just runs once and not invoke the next one and you can see in the prints in the logs from last screenshot that the if statement is true so it should invoke another instance of the method right?

It’s very hard to troubleshoot since it only happens randomly and it doesn’t return an error when it happens either.

I would add more logs to see where exactly it breaks

I agree, I still believe it might happen because of async invocation

the async code runs when the worker is about to be killed, but to be sure you need to add a print before the recur method runs inside the async code

if the issue with async you can add wait(0) in the end of the logic to allow run all async code before killing the working

I will try this. Thank you so much :slightly_smiling_face:

@vladimir-upirov
I’ve added the print.


It happened again and the print is showing up

So I added the wait(0), in the first screenshot. Is how I added it right?

@DALDE_John you need to put the wait block right after the Run code async block, not inside it.

1 Like

I’ve been monitoring the whole week and there have been no errors so far. Thanks so much for the help

1 Like