簡體   English   中英

客戶端python可以使用線程嗎?

[英]Can client side python use threads?

我以前從未使用過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>

當前的答案是(2009年6月19日,星期五),是的,它可以運行線程,但是除了主線程之外,其他都不能訪問JavaScript對象,其中包括DOM。 因此,如果您打算使用線程應用程序更新UI,那是不可能的。 在Appcelerator團隊創建到主線程的某種隊列之前,可以通過綁定系統。

請在appcelerator論壇上查看討論。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM