客户端Python可以使用线程?
-
13-09-2019 - |
题
我从来没有在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的论坛讨论。
不隶属于 StackOverflow