简体   繁体   English

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

[英]Can client side python use threads?

I have never programed in Python before, so excuse my code. 我以前从未使用过Python编程,请原谅我的代码。 I have this script that will run in a terminal but I can't get it to run client side. 我有此脚本将在终端中运行,但无法使其在客户端运行。 I am running this in Appcelerator's Titanium application. 我正在Appcelerator的Titanium应用程序中运行它。 Anyway, I have been troubleshooting it and it seems that it isn't running the threads at all. 无论如何,我一直在对它进行故障排除,似乎它根本没有运行线程。 Is this a limitation? 这是一个限制吗? does anyone know? 有人知道吗?

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

The answer, currently (Friday, June 19th, 2009) is yes, it can run threads, but the nothing but the main thread can access JavaScript objects, this includes the DOM. 当前的答案是(2009年6月19日,星期五),是的,它可以运行线程,但是除了主线程之外,其他都不能访问JavaScript对象,其中包括DOM。 so if you are planning on updating the UI with a threading app, this is not possible... YET. 因此,如果您打算使用线程应用程序更新UI,那是不可能的。 Until the Appcelerator team creates some sort of queue to the main thread, possible via a binding system. 在Appcelerator团队创建到主线程的某种队列之前,可以通过绑定系统。

Please see discussion at the appcelerator forums . 请在appcelerator论坛上查看讨论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM