Thread get off from CPU occasionally. I suspect.

R

Rajat

Hi,

I'm using Python 2.6 and using the threading module.
In a python module (parent module) I'm importing main() function from
another python module. I'm runnin this main() function on a Python
thread so that I can periodically check in the parent thread/module if
the new thread is up and running. This information that the python
script running on the new thread is still up and running is passed to
a 3rd party application (in a manner known to 3rd party).

As 3rd party is waiting for this new thread to finish. It waits for 3
mins and on told to it by the parent thread that new thread is still
running, the 3rd party then starts to wait again for 3 mins.

I've successfully implemented this functionality and it runs well
except for a rare chance when the new thread does not completely runs.
However, most of the cases the new thread runs completely. I cannot
understand why and when the new thread gets off the CPU or crashes or
any other thing?

I'm not able to figure out what is happening.?

The code in the parent thread that starts the new thread is as
follows?

exec("from " + passed_script_file + " import main") #imported main
function. It works.
import threading
import time
p = RunTestScript(main)
p.start()
t_nought = time.time()
logSystemInfo(t_nought)
seconds_passed = 0
keep_alive_set = 0
while p.isAlive() == True:
p.join(60.0)
if p.isAlive() == True:
seconds_passed = time.time() - t_nought
if seconds_passed >= 120:
t_nought = time.time()
if keep_alive_set != 1: # 3rd party way of informing
that the new thread is alive.
request = 'SET SHARED VAR KEEP_ALIVE=%d' %(1)
res = handle.submit('local', 'VAR', request)
if (res.rc != 0):
logSystemError('[PyInt] Error: STAF local VAR %s
failed, RC: %s, Result: %s\n' % (request, res.rc,
res.result))
return res.rc
keep_alive_set = 1



Earlier, when I did not run the main function on a new thread, it
always used to run completely. I used to run it as:

exec("from " + passed_script_file + " import main")
retCode = main()



Thanks and regards,
Rajat
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top