我以前从未用 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>