Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
客户端python可以使用线程吗?_Python_Multithreading_Client Side_Titanium_Appcelerator - Fatal编程技术网

客户端python可以使用线程吗?

客户端python可以使用线程吗?,python,multithreading,client-side,titanium,appcelerator,Python,Multithreading,Client Side,Titanium,Appcelerator,我以前从未用Python编程,所以请原谅我的代码。我有这个脚本将在终端中运行,但我无法让它在客户端运行。我在Appcelerator的钛应用程序中运行这个。无论如何,我一直在对它进行故障排除,它似乎根本没有运行线程。这是限制吗?有人知道吗 <script type="text/python"> import os import sys import Queue import threading class FindThread ( threading.Thread ): def

我以前从未用Python编程,所以请原谅我的代码。我有这个脚本将在终端中运行,但我无法让它在客户端运行。我在Appcelerator的钛应用程序中运行这个。无论如何,我一直在对它进行故障排除,它似乎根本没有运行线程。这是限制吗?有人知道吗

<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>

导入操作系统
导入系统
导入队列
导入线程
类FindThread(threading.Thread):
def运行(自):
运行=真
运行时:
如果作业池为空():
#打印“>打开螺纹”
FindThread().start()
def目录搜索(top=“.”):
导入操作系统、统计数据、类型
name=os.listdir(顶部)
对于名称中的名称:
尝试:
st=os.lstat(os.path.join(top,name))
除操作系统错误外:
持续
如果stat.S_ISDIR(st.st_模式):
jobbool.put(os.path.join(top,name))
其他:
window.document.getElementById('output').innerHTML+=os.path.join(顶部,名称)
window.findPython=findPython
目前(2009年6月19日,星期五)的答案是肯定的,它可以运行线程,但除了主线程之外,什么都不能访问JavaScript对象,这包括DOM。因此,如果您计划使用线程应用程序更新UI,这是不可能的。。。然而直到Appcelerator团队创建到主线程的某种队列(可能通过绑定系统)

请参见第页的讨论