2009-06-14 86 views
0

我從來沒有在Python編程過,所以請原諒我的代碼。我有這個腳本會在終端中運行,但我無法運行它來運行客戶端。我正在Appcelerator的Titanium應用程序中運行它。無論如何,我一直在解決它,它似乎並沒有運行線程。這是一個限制嗎?有人知道嗎?客戶端python可以使用線程嗎?

<script type="text/python"> 
import os 
import sys 
import Queue 
import threading 
class FindThread (threading.Thread): 
    def run (self): 
     running = True 
     while running: 
     if jobPool.empty(): 
      #print '<< CLOSING THREAD' 
      running = False 
      continue 

     job = jobPool.get() 
     window.document.getElementById('output').innerHTML += os.path.join(top, name) 
     if job != None: 
      dirSearch(job)    

jobPool = Queue.Queue (0) 

def findPython(): 
    #output = window.document.getElementById('output') 
    window.document.getElementById('output').innerHTML += "Starting" 
    dirSearch("/") 
    # Start 10 threads: 
    for x in xrange (10): 
     #print '>> OPENING THREAD' 
     FindThread().start() 

def dirSearch(top = "."): 
    import os, stat, types 
    names = os.listdir(top) 
    for name in names: 
     try: 
      st = os.lstat(os.path.join(top, name)) 
     except os.error: 
      continue 
     if stat.S_ISDIR(st.st_mode): 
      jobPool.put(os.path.join(top, name)) 
     else: 
      window.document.getElementById('output').innerHTML += os.path.join(top, name) 

window.findPython = findPython 

</script> 

回答

2

答案,目前(星期五,2009年6月19日)是肯定的,它可以運行的線程,但也不過主線程可以訪問JavaScript對象,這包括DOM。所以如果你打算用線程應用更新UI,這是不可能的......是的。直到Appcelerator團隊創建某種類型的隊列到主線程,可能通過綁定系統。

請參閱​​的討論。

相關問題