Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
RokuNB
Roku Guru

Re: Execution TimeOut in a task

"destruk" wrote:
You might need to drop the Roku2 - Roku3s and Roku4s don't behave this way.

To me seems like a bad advice, giving up easily on this. I don't know of related limitation here and trust if there is one, we'd document/announce it. What's happening here might be a race condition that does not happen on multi-core players because of timing - but i am fairly certain even if it is a bug there would be a way to avoid it by reshuffling some code
0 Kudos
btpoole
Channel Surfer

Re: Execution TimeOut in a task

"RokuNB" wrote:
"destruk" wrote:
You might need to drop the Roku2 - Roku3s and Roku4s don't behave this way.

To me seems like a bad advice, giving up easily on this. I don't know of related limitation here and trust if there is one, we'd document/announce it. What's happening here might be a race condition that does not happen on multi-core players because of timing - but i am fairly certain even if it is a bug there would be a way to avoid it by reshuffling some code

I appreciate your response but as I have stated, I moved all heavy lifting from the roku to the server. The only process the roku has to do is a urlTransfer of a 350 kb file, run thru a for loop and display the content. When the app starts, it does the process with no hesitation in the main.brs. Later in the code to keep the content updated, a urlTransfer is made to the server to do the same process as in the start up. This is when the execution timeout occurs. I have tried to run the same process thru a task back to the main as well as created a new function outside the main in a task but get the same results. As for giving up easily, I have spent the better part of a solid week on this one error which should not be occurring.  When you say a "race condition", would it be that a wait be instigated? I was using observerfield to check the state of the task, not continuing until the task state was stop. Thanks again
0 Kudos
Veeta
Visitor

Re: Execution TimeOut in a task

"btpoole" wrote:
task_gridcontent.xml

<?xml version="1.0" encoding="utf-8" ?>
<!--********** Copyright 2016 Roku Corp.  All Rights Reserved. **********-->
<component name = "resetgrid" extends = "Task" >
  <interface>
    <field id = "ProgramContent" type = "node" />
      </interface>

 <script type="text/brightscript" uri="pkg:/source/main.brs" />
 <script type="text/brightscript" uri="pkg:/components/home/setupcontent.brs" />
 <script type="text/brightscript" uri="pkg:/components/home/content.brs" />
<script type="text/brightscript" uri="pkg:/components/timeutility/timeutility.brs" />
<script type="text/brightscript" uri="pkg:/components/setup_variable.brs" />
  <script type = "text/brightscript" >
    <![CDATA[

    sub init()
PRINT "IN resetgrid  TASK"
m.currentTime=getCurrentTime()  'CURRENT TIME IN SECONDS
upDateGrid()
end sub


function upDateGrid()
i=0
?"in UpDateGrid"
m.showcontent=createobject("roSGNode", "ContentNode")
for each items in m.roProgramlist.items
  for each show in items.show
if show.start >= m.currentTime and m.currentTime <= show.end
i=i+1
?i
dataitem=m.showcontent.Createchild("ContentNode")
dataitem.addfields({"title" : show.title})
dataitem.addfields({"desc" : show.dec})
else
end if
end for
end for
m.top.ProgramContent=m.showcontent
end function
]]>
  </script>
</component>



Function that calls task
sub resetgrid()
m.spinner.control="start"
m.spinner.visible=true[/font][/size]
m.updateGrid = createObject("RoSGNode","resetgrid")
m.updateGrid.ObserveField("state", "resetcontent")
m.updateGrid.control = "RUN"
end sub

function resetcontent()
if m.updateGrid.state = "stop"
setcolumnWidth()
m.programmarkupgrid.content= m.updateGrid.ProgramContent
m.spinner.control= "stop"
m.spinner.visible=false
m.spinnerlabel.visible=false
m.ProgramMarkupGrid.visible=true
m.programmarkupgrid.SetFocus(true)
else
end if
end function

Here is the task, the calling function and the callback. The debugger shows the execution error occurs in the task, but not always on the same line of the task.

Calling updateGrid within init() causes it to run in the render thread, which is probably not what you're trying to do.  You need to set m.top.functionName = "updateGrid" within init() and then it will run in the background thread.  
Put a console print statement right before and after your line with CreateObject("roSGNode", "resetgrid") and you'll probably see that it stops within that function, as init() is executed for the newly created task node.
0 Kudos
btpoole
Channel Surfer

Re: Execution TimeOut in a task

"Veeta" wrote:
"btpoole" wrote:
task_gridcontent.xml

<?xml version="1.0" encoding="utf-8" ?>
<!--********** Copyright 2016 Roku Corp.  All Rights Reserved. **********-->
<component name = "resetgrid" extends = "Task" >
  <interface>
    <field id = "ProgramContent" type = "node" />
      </interface>

 <script type="text/brightscript" uri="pkg:/source/main.brs" />
 <script type="text/brightscript" uri="pkg:/components/home/setupcontent.brs" />
 <script type="text/brightscript" uri="pkg:/components/home/content.brs" />
<script type="text/brightscript" uri="pkg:/components/timeutility/timeutility.brs" />
<script type="text/brightscript" uri="pkg:/components/setup_variable.brs" />
  <script type = "text/brightscript" >
    <![CDATA[

    sub init()
PRINT "IN resetgrid  TASK"
m.currentTime=getCurrentTime()  'CURRENT TIME IN SECONDS
upDateGrid()
end sub


function upDateGrid()
i=0
?"in UpDateGrid"
m.showcontent=createobject("roSGNode", "ContentNode")
for each items in m.roProgramlist.items
  for each show in items.show
if show.start >= m.currentTime and m.currentTime <= show.end
i=i+1
?i
dataitem=m.showcontent.Createchild("ContentNode")
dataitem.addfields({"title" : show.title})
dataitem.addfields({"desc" : show.dec})
else
end if
end for
end for
m.top.ProgramContent=m.showcontent
end function
]]>
  </script>
</component>



Function that calls task
sub resetgrid()
m.spinner.control="start"
m.spinner.visible=true[/font][/size]
m.updateGrid = createObject("RoSGNode","resetgrid")

m.updateGrid.ObserveField("state", "resetcontent")
m.updateGrid.control = "RUN"
end sub

function resetcontent()
if m.updateGrid.state = "stop"
setcolumnWidth()
m.programmarkupgrid.content= m.updateGrid.ProgramContent
m.spinner.control= "stop"
m.spinner.visible=false
m.spinnerlabel.visible=false
m.ProgramMarkupGrid.visible=true
m.programmarkupgrid.SetFocus(true)
else
end if
end function

Here is the task, the calling function and the callback. The debugger shows the execution error occurs in the task, but not always on the same line of the task.

Calling updateGrid within init() causes it to run in the render thread, which is probably not what you're trying to do.  You need to set m.top.functionName = "updateGrid" within init() and then it will run in the background thread.  
Put a console print statement right before and after your line with CreateObject("roSGNode", "resetgrid") and you'll probably see that it stops within that function, as init() is executed for the newly created task node.

Thank you Veeta, I will definately try this.  I didn't realize calling it directly would cause this problem. Thanks again

UPDATE: Thanks to Veeta's suggestion of m.top.functionName in place of calling the function directly,  no more crashing. Thanks again.
0 Kudos
chaklasiyanikun
Roku Guru

Re: Execution TimeOut in a task

Hello, I'm new to Roku. I'm getting the same issue(Execution TimeOut) with the Task node. I created one Timer in the Scene node for Continuous Execute Function Here I Tried With Continuous Response Update With Task node and After It used in Scene Node.

'Timer

m.Update = m.top.findNode("SampleID")
m.Update .observeField("fire", "UpdateSample")
m.global.responseurl = m.urlassign
m.Update.control = "RUN"

'My Function

function UpdateSample()
	m.Sample= CreateObject("roSGNode", "SampleTask")
        m.Sample.control = "RUN"
        ?"m.global.responsecontent : " m.global.responsecontent 
end function 

'My Task Node

sub init()
?"Start Init()"
    m.DowndloadResponse = CreateObject("roUrlTransfer")
    m.DowndloadResponse.SetUrl(m.global.responseurl)
    m.Cont= m.DowndloadResponse.GetToString()
    m.global.responsecontent = m.Cont
    ?"m.global.responsecontent : " m.global.responsecontent 
?"End Init()"
end sub

Here, Not getting every time DowndloadResponse.GetToString() "Execution TimeOut". Sometimes It Gives the Error. I tried with m.top.functionname. But It's Execution at once. I also Tried with Timer Set in Task Node. But No luck. I required It's multiple. I don't know Which one is a good way to implement this.
Does Anyone any idea how do solve this problem?

0 Kudos
renojim
Community Streaming Expert

Re: Execution TimeOut in a task

I would use AsyncGetToString(). Create a message port, assign it to the URL transfer object and then wait on it for a few seconds.  Something like this:

 

m.DowndloadResponse = CreateObject("roUrlTransfer")
m.DowndloadResponse.SetUrl(m.global.responseurl)
port = CreateObject("roMessagePort")
m.DowndloadResponse.SetPort(port)
m.DowndloadResponse.AsyncGetToString()
msg = wait(port,3000)
if msg = invalid then 
  ' transfer failed
m.DowndloadResponse.AsyncCancel()
else
m.global.responsecontent = msg.GetString()
end if

You'll probably want to add more error checking.

 

-JT

 

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
chaklasiyanikun
Roku Guru

Re: Execution TimeOut in a task

Thank you for your great Reply. It's Works. But Sometimes I send the Wrong URL in 

m.global.responseurl 'like spelling mistake or some character missing
m.DowndloadResponse.SetUrl(m.global.responseurl)

Is there any way to check the response URL, It's proper or not?. I check below value But It's not waiting for a complete response and msg = wait(0, port) give execution timeout again. I read the Documentation. But no luck.

m.DowndloadResponse.AsyncGetToString()

 I also tried with like msg <> invalid. But It's before execution. It gives Execution timeout Error here 

msg = wait(0,port) 

I also set retainBodyOnError like below before SetUrl and tried to manage But no luck

m.DowndloadResponse.retainBodyOnError(true)

Any Solution for that.

0 Kudos
renojim
Community Streaming Expert

Re: Execution TimeOut in a task

I see I had a typo in my example.  It should have been:

 

msg = wait(3000,port)

If you have wait(0,port), you're basically telling it to wait forever, hence the execution timeout.  In my example it will wait for no more than 3000ms (i.e., 3 seconds).

 

I've used Head() to do a "quick" check before doing the actual transfer, but you'll still want to use the Async version:

 

m.DownloadResponse.AsyncHead()
msg = wait(1000,port)  ' shouldn't take more than a second I'd imagine
if msg = invalid then
   ' timeout occurred, so something's wrong
else
  ' try real transfer
  m.DownloadResponse.AsyncGetToString()
  msg = wait(3000,port)
  if msg = invalid then
  ... 

I'm not clear on what you're asking about retainBodyOnError, but fix the wait(0,port) problem first and see how that goes.

 

-JT

 

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
chaklasiyanikun
Roku Guru

Re: Execution TimeOut in a task

Hello @renojim , I tried with the below Approach For Fetching a response using roUrlTransfer. (My Request is "Post". But, Not Require to pass any parameter using the header. I entered my URL in the browser then below it display a response. My response is only if pass valid URL then "true". if pass, not valid URL then "false") Here My Device internet download speed: Good(8 Mbps). Even So, In My Roku device fetching Execution error. My other device internet download speed: Good(10 Mbps). It's not fetching an error. My device is Roku Premiere plus.

m.readdata = CreateObject("roUrlTransfer") 
data = "MyURL"
m.readdata.EnableEncodings(true)
m.readdata.setUrl(data)
? "data is " data
m.port = CreateObject("roMessagePort")
m.readdata.setport(m.port)
m.readdata.gettostring()
?"Login.brs -readdata.gettostring() : " m.readdata.gettostring()
m.readdata.SetRequest("POST") 
request = m.readdata.AsyncPostFromString(data)
while (true)
     ? "start of while"
     msg = Wait(3000, m.port) 
     statusCode = msg.GetResponseCode() 
     ?"StatusCode :"statusCode
     if (Type(msg) = "roUrlEvent")
          statusCode = msg.GetResponseCode()
          ?"Inside IF :: statusCode : " statusCode
          headers = msg.GetResponseHeaders()
          ?"Inside IF :: headers : " headers
          if msg.getresponsecode() = 200 then
               data = msg.getstring()
               headers = msg.getresponseheadersarray()
               print "***************DATA*********************"
               print data
               print "****************************************"
               ? "statusCode value here : " statusCode
               exit while
          else
               m.readdata.asynccancel()
               exit while
          end if
     else
          ? "do somthing useful while we wait for data"
     end if
end while

I also tried your approach. As mentioned above. And Here I put in below. But, every time I get m.readdata.AsyncGetToString() value = false. I know this is not waiting until a completed response. But, Here I fetch every time wrong("false") response. Is there any reason behind it. It should come invalid if my speed is not good. But, every time I found false value. I checked the same API in API testing tools, different browsers, and different platforms. It's Working fine. But, I don't know why this has happened with Roku.

m.readdata = CreateObject("roUrlTransfer")
m.readdata.SetUrl(MyURL)
m.port = CreateObject("roMessagePort")
m.readdata.setport(m.port)
m.readdata.SetRequest("POST") 
'm.readdata.AsyncHead()
m.readdata.AsyncGetToString()
'?"m.readdata.AsyncHead() : "m.readdata.AsyncHead() 'Here I always Found false. ?"m.readdata.AsyncGetToString() : "m.readdata.AsyncGetToString() 'Here I always Found false.
msg = wait(3000,m.port) if msg = invalid then ' transfer failed m.readdata.AsyncCancel() else ?"msg.GetString() : " msg.GetString() end if 

 

0 Kudos
renojim
Community Streaming Expert

Re: Execution TimeOut in a task

m.readdata.AsyncGetToString()
'?"m.readdata.AsyncHead() : "m.readdata.AsyncHead() 'Here I always Found false. ?"m.readdata.AsyncGetToString() : "m.readdata.AsyncGetToString() 'Here I always Found false.

You've started an async transfer and then you try to start another before the first one has a chance to finish or time out.  You can only do one at a time.

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.