Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Korakot Chaovavanich http://korakot.stumbleupon.com

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Keep light on using thread

Copy-paste version
   1  
   2  import e32, miso, thread
   3  running = 1
   4  def lighton():
   5    while running:
   6      miso.reset_inactivity_time()
   7      e32.ao_sleep(5)
   8  
   9  thread.start_new_thread(lighton, ())
  10  # end by set running = 0


2 functions (lighton, lightoff) version.
   1  
   2  import e32
   3  import miso
   4  import thread
   5  
   6  flag = 1
   7  def _lighton():
   8      while flag:
   9          miso.reset_inactivity_time()
  10          e32.ao_sleep(5)
  11  
  12  def lighton():
  13      thread.start_new_thread(_lighton, ())
  14  
  15  def lightoff():
  16      global flag
  17      flag = 0

Simple thread in python

Taken from this article.

   1  
   2  import time
   3  import thread
   4  
   5  def myfunc(string,sleeptime):
   6      while 1:
   7          print string
   8          time.sleep(sleeptime)
   9  
  10  thread.start_new_thread(myfunc,("Thread No:1",2))
  11  # Then do other things.
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS