2009-06-14 3 views
0

필자는 전에 Python으로 프로그래밍 한 적이 없으므로 코드를 사용 해보십시오. 터미널에서 실행할이 스크립트가 있지만 클라이언트 쪽을 실행하도록 가져올 수 없습니다. 나는 Appcelerator의 Titanium 응용 프로그램에서 이것을 실행하고 있습니다. 어쨌든, 나는 그것의 문제를 해결하고 그것은 전혀 스레드를 실행하지 않는 것 같습니다. 이것이 한계입니까? 아는 사람 있나요?클라이언트 측 파이썬은 스레드를 사용할 수 있습니까?

<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

대답은, 네, 스레드를 실행할 수 있습니다,하지만 메인 쓰레드하지만 아무것도 자바 스크립트 객체에 액세스 할 수 없습니다 현재 (금요일, 6 월 19 일, 2009), 이것은 DOM을 포함한다. 따라서 스레딩 응용 프로그램을 사용하여 UI를 업데이트 할 계획이라면 불가능합니다 ... 그렇습니다. Appcelerator 팀이 바인딩 시스템을 통해 주 스레드에 대기열을 만들 때까지

appcelerator forums에서 토론을 참조하십시오.

관련 문제