SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-18-2006, 12:15 PM
Opus4's Avatar
Opus4 Opus4 is offline
Administrator
 
Join Date: Sep 2003
Location: NJ
Posts: 19,624
Exiting global forked threads that loop

In case anyone else is using a global forked thread that loops the entire time that SageTV is running...

I recently noticed that a forked loop was continuing to run on my SageTV server after a Placeshifter or MVP client disconnected. This particular loop (to update the disk space usage info) was a global loop, meaning it wasn't linked to any particular menu's hooks and did not shut off via a variable setting when the menu was exited. This is not an issue for a local client UI, because when you exit the program, all code associated with that program will cease to execute. But, since remote clients run as part of the server application, exiting the remote client will not automatically kill the permanent global loop on the server. As multiple remote clients connect & disconnect, these background loops can easily multiply and eat cpu time. Thus, all forked threads need to be able to exit their loops when a client disconnects. If any other globally looping threads have this issue, there are at least a couple ways this can be done:
  1. Use the ApplicationExiting hook to set a global variable that tells the global loop that it should end. This is probably better than using UI context names (described below), since all clients should execute the ApplicationExiting hook when they disconnect, thus preventing any possibility of multiple loops continuing to run. (I have not used this method yet, so you should test it to make sure it is working to exit your loop on a remote client.)

  2. Check the UI context -- Before continuing a global loop, use GetUIContextNames() to get all UI context names, use GetUIContextName() to get the current UI context, then check to see if the current UI context is still in the list of all context names. If it isn't, then the remote client has exited and the loop should end. Note: Depending on how quickly the UI contexts are checked, it is possible to reconnect a remote client before the loop sees that it has exited. This could result in the loop thinking that it should still be running, even though it can't talk to the reconnected remote client. In this case, you could end up with multiple forked loops, but they should all end when the remote client disconnects for longer than the loop's Wait() period.

A 'just in case' reminder: don't forget to make sure all non-global hooks that are linked to specific menus also stop themselves eventually. This is usually done by setting a variable in the BeforeMenuUnload hook that tells the local loop to end because the menu no longer needs it.

- Andy
__________________
SageTV Open Source v9 is available.
- Read the SageTV FAQ. Older PDF User's Guides mostly still apply: SageTV V7.0 & SageTV Studio v7.1.
- Hauppauge remote help: 1) Basics/Extending it 2) Replace it 3) Use it w/o needing focus
- HD Extenders: A) FAQs B) URC MX-700 remote setup
Note: This is a users' forum; see the Rules. For official tech support fill out a Support Request.
Reply With Quote
  #2  
Old 12-18-2006, 04:35 PM
dflachbart dflachbart is offline
SageTVaholic
 
Join Date: Jan 2006
Location: Brookfield, CT
Posts: 2,743
Quote:
Originally Posted by Opus4
  1. Use the ApplicationExiting hook to set a global variable that tells the global loop that it should end. This is probably better than using UI context names (described below), since all clients should execute the ApplicationExiting hook when they disconnect, thus preventing any possibility of multiple loops continuing to run. (I have not used this method yet, so you should test it to make sure it is working to exit your loop on a remote client.)
I just updated the SageMC code using this approach, and it works perfectly. Thanks for the info !

Dirk
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 02:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.