Showing posts with label Webware. Show all posts
Showing posts with label Webware. Show all posts

Wednesday, March 30, 2011

Webware taskkit keep process executing without loading system

Here is my taskkitsample.py:

from TaskKit.Scheduler import Scheduler
from TaskKit.Task import Task
from time import time, strftime, localtime, sleep
     
class SimpleTask(Task):
    def run(self):
      print "hola "
      print self.name(), strftime("%H:%M:%S", localtime(time()))

def main():
    scheduler = Scheduler()
    scheduler.start()
    scheduler.addPeriodicAction(time(), 1 , SimpleTask(), 'Test')

main()




If I run from command line:

python taskkitsample.py

The process stops inmmediately: 



one common way to keep the process running is by adding the while True loop:

def main():
    scheduler = Scheduler()
    scheduler.start()
    scheduler.addPeriodicAction(time(), 1 , SimpleTask(), 'Test')

    while True:
        pass



Yeah, It works:



But If you take a look to the Task Administrator, there is a big problem: the CPU % use!!!:

The solution is quite simple, do not insert the while True: sentence in your code and run the python file using -i:


Works Much Better :D

Reference: http://stackoverflow.com/questions/1000900/how-to-keep-a-python-script-output-window-open