Python Forum
Code issue with time remaining loop. Python3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code issue with time remaining loop. Python3
#6
it looks like that works fine. i extended the code into my main program but is giving me issues still.

import time
import multiprocessing
import queue
 
def cleancycle(clean,seconds):
    msgqueue=multiprocessing.Queue()
    ctr=multiprocessing.Process(target=timeremaining,args=(seconds,msgqueue))
    ctr.daemon=True
    if not ctr.is_alive:
        ctr.start()
    print('clean')
    print('Queue: {}'.format(msgqueue))
    if clean=='1':
        print('clean is one')
        pass
    else:
        msgqueue.put('stop')
        
def timeremaining(seconds=0,msgqueue=None):
    print('Time: {}'.format(seconds))
    print('Queue: {}'.format(queue))
    while seconds != 0:
        print('time remaining: {}'.format(seconds))
        seconds-=1
        time.sleep(1)
        try:
            msg=msgqueue.get(False)
            if msg=='stop':
                print('Exit loop')
                break
        except queue.Empty:
            pass
def main():
    i=0
    seconds=100
    cleancycle('1',seconds)
    for i in range(0,30):
        print (i)
        i+=1
        time.sleep(1)
    cleancycle('2',seconds)
        
        
 
if __name__ == '__main__':
    main()
the issue im now facing is that it doesnt print time remaining. if you have any ideas to maybe restructure the program instead of reprogramming stuff that would be fine too
Reply


Messages In This Thread
RE: Code issue with time remaining loop. Python3 - by deboerdn2000 - May-03-2017, 11:00 PM
queue not passing updated message - by deboerdn2000 - May-03-2017, 07:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Updating Code And Having Issue With Keys Xileron 8 1,268 May-25-2023, 11:14 PM
Last Post: DigiGod
  Python3 for loop over a dict ogautier 3 1,434 Feb-25-2022, 10:17 AM
Last Post: Larz60+
  NameError issue with daughter's newb code MrGonk 2 1,485 Sep-16-2021, 01:29 PM
Last Post: BashBedlam
  Calculator code issue using list kirt6405 4 2,326 Jun-11-2021, 10:13 PM
Last Post: topfox
  How to measure execution time of a multithread loop spacedog 2 2,925 Apr-24-2021, 07:52 AM
Last Post: spacedog
  Assistance with running a few lines of code at an EXACT time nethatar 5 3,339 Feb-24-2021, 10:43 PM
Last Post: nilamo
  Stumped by my own code (ratio & epoch-time calculation). MvGulik 2 2,179 Dec-30-2020, 12:04 AM
Last Post: MvGulik
  Code taking too much time to process ErPipex 11 5,016 Nov-16-2020, 09:42 AM
Last Post: DeaD_EyE
  What is the run time complexity of this code and please explain? samlee916 2 2,329 Nov-06-2020, 02:37 PM
Last Post: deanhystad
  The count variable is giving me a hard time in this code D4isyy 2 1,997 Aug-09-2020, 10:32 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020