#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Process running every second + a 2nd one to pull value


    Hi guys,

    I am trying to have one timer going, executing code every second and updating the value of a variable. At the same time, I want to do an ad-hoc pull (via WSIG) of the value to bring it to the web.

    Essentially I want the value of a variable updating constantly, but being able to pull it at a given time via another function (thread?).

    What should my approach be?

    Thanks in advance!
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,701
    Rep Power
    480
    I hope someone comes up with a good answer or explains that my answer is "good".
    Code:
    #code restored
    import signal
    import threading
    import time
    
    a = 0
    more = True
    semaphore = threading.Semaphore()
    
    def change():
        global a,more
        for i in range(8):
            a = i
            semaphore.release()
            time.sleep(1)
        more = False
        semaphore.release()
    
    threading.Thread(target=change).start()
    
    old = a
    while more:
        semaphore.acquire()
        print(a)
        old = a
    Last edited by b49P23TIvg; November 7th, 2012 at 09:07 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo