Thread get off from CPU occasionally. I suspect.

Discussion in 'Python' started by Rajat, Jan 29, 2010.

  1. Rajat

    Rajat Guest

    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
     
    Rajat, Jan 29, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. S. Justin Gengo
    Replies:
    0
    Views:
    729
    S. Justin Gengo
    Aug 5, 2003
  2. BradC
    Replies:
    4
    Views:
    527
    Jim Cheshire [MSFT]
    Nov 12, 2004
  3. Vijay Kumar
    Replies:
    3
    Views:
    518
    zn├┤rt
    Feb 4, 2004
  4. stacey
    Replies:
    11
    Views:
    644
    Adam Maass
    Mar 6, 2007
  5. Dave
    Replies:
    1
    Views:
    384
    Jesse Houwing
    Aug 3, 2007
Loading...

Share This Page