Je n'ai jamais programmé en Python auparavant, alors excusez mon code. J'ai ce script qui fonctionnera dans un terminal mais je ne peux pas le faire fonctionner côté client. Je cours cela dans l'application Titanium d'Appcelerator. Quoi qu'il en soit, je l'ai dépanné et il semble qu'il ne fonctionne pas du tout les threads. Est-ce une limitation? est-ce que quelqu'un sait?Est-ce que python côté client peut utiliser des threads?
<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>