Thread API: Thread stops working (dies?) after 30 minutes

Hi,

 

  Simple thread usage implementation:

def Start():
#Create a thread for the PVR functionality
Thread.Create(PVR)

#Lots of other initialisation code here...

return

def PVR():
Log.Info(‘PVR: PVR starting’)

#This thread never stops
while (True):
    now = dt.datetime.now()
    Log.Info('PVR: PVR while loop at ' + str(now))

    #Sleep for 60 seconds
    Thread.Sleep(float(60))

return

Typical log file for the plugin:

2013-12-26 13:17:27,171 (1100a4000) :  INFO (__init__:75) - PVR: PVR starting
2013-12-26 13:18:27,171 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:18:27.171686
2013-12-26 13:19:27,171 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:19:27.171751
2013-12-26 13:20:27,171 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:20:27.171451
2013-12-26 13:21:27,171 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:21:27.171368
2013-12-26 13:22:27,170 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:22:27.170665
2013-12-26 13:23:27,170 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:23:27.170213
2013-12-26 13:24:27,170 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:24:27.170159
2013-12-26 13:25:27,169 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:25:27.169380
2013-12-26 13:26:27,168 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:26:27.168774
2013-12-26 13:27:27,168 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:27:27.168586
2013-12-26 13:28:27,167 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:28:27.167655
2013-12-26 13:29:27,166 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:29:27.166821
2013-12-26 13:30:27,166 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:30:27.166765
2013-12-26 13:31:27,166 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:31:27.166119
2013-12-26 13:32:27,165 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:32:27.165808
2013-12-26 13:33:27,165 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:33:27.165028
2013-12-26 13:34:27,165 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:34:27.165341
2013-12-26 13:35:27,165 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:35:27.165371
2013-12-26 13:36:27,165 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:36:27.165015
2013-12-26 13:37:27,164 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:37:27.164264
2013-12-26 13:38:27,164 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:38:27.164333
2013-12-26 13:39:27,164 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:39:27.164441
2013-12-26 13:40:27,164 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:40:27.164204
2013-12-26 13:41:27,163 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:41:27.163807
2013-12-26 13:42:27,163 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:42:27.163712
2013-12-26 13:43:27,163 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:43:27.163757
2013-12-26 13:44:27,163 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:44:27.163763
2013-12-26 13:45:27,163 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:45:27.163409
2013-12-26 13:46:27,162 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:46:27.162741
2013-12-26 13:47:27,162 (1100a4000) :  INFO (__init__:80) - PVR: PVR while loop at 2013-12-26 13:47:27.162610

Question: Why does the thread (or the plugin?) stop after about 30 minutes? I would like to have a thread that is running as long as the PMS is running. Is this possible?

 

PMS normally kills off plugin processes after they have been “unused” for a while (apparently about a half hour). To avoid this and allow your plugin to run in the background, you’ll need to add a flag to the plugin’s Info.plist file.

PlexPluginMode
Daemon

Thanks! That solved my problem.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.