클라이언트 측 파이썬이 스레드를 사용할 수 있습니까?
-
13-09-2019 - |
문제
전에는 Python으로 프로그래밍 한 적이 없으므로 코드를 실례합니다. 터미널에서 실행되는이 스크립트가 있지만 클라이언트 측면을 실행할 수는 없습니다. Appcelerator의 Titanium Application에서 이것을 실행하고 있습니다. 어쨌든, 나는 그것을 문제 해결하고 있었고 그것이 스레드를 전혀 실행하지 않는 것 같습니다. 이것이 제한입니까? 아는 사람 있나요?
<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