0

Im trying to execute a program in a python subprocess:

class MiThread(threading.Thread):  
      def __init__(self):  
          threading.Thread.__init__(self)   

      def run(self):
        try:
            from Queue import Queue, Empty
        except ImportError:
    #from queue import Queue, Empty  # python 3.x
            print "error"
        ON_POSIX = 'posix' in sys.builtin_module_names

        def enqueue_output(out, queue):
            for line in iter(out.readline, b''):
                queue.put(line)
            out.close()
        p= Popen(["java -Xmx256m -jar bin/HelloWorld.jar"],cwd=r'/home/karen/sphinx4-1.0beta5-src/sphinx4-1.0beta5/',stdout=PIPE, shell=True, bufsize= 4024)
        q = Queue()
        t = Thread(target=enqueue_output, args=(p.stdout, q))
        print "estoy en el hilo"
        t.daemon = True # thread dies with the program
        t.start()

                print l

But when i execute the thread it fails with the following error:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/site-packages/GNS3/Workspace.py", line 65, in run
    t = Thread(target=enqueue_output, args=(p.stdout, q))
NameError: global name 'Thread' is not defined

QObject::connect: Cannot queue arguments of type 'QTextCursor'
(Make sure 'QTextCursor' is registered using qRegisterMetaType().)

i dont have any idea! What is happening?

1 Answer 1

2

Try changing:

t = Thread(target=enqueue_output, args=(p.stdout, q))

to:

t = threading.Thread(target=enqueue_output, args=(p.stdout, q))

In your current namespace, Thread exists as threading.Thread (a member of the threading module), so when you say Thread alone, Python can't find a match and throws that error.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you @RocketDonkey i fixed Thread's error! But the following error is occuring yet:QObject::connect: Cannot queue arguments of type 'QTextCursor' (Make sure 'QTextCursor' is registered using qRegisterMetaType().) Any idea?
@karensantana Glad to hear it - as for the second error, that looks like a QT-related issue, and unfortunately I know literally nothing about it :) However I did a quick search, and it appears that you need to both create and register meta types, and from the code examples I saw, it is not done in Python (this is only based on ~5 minutes of research though - I could be missing something). Not sure if this (doc.qt.digia.com/4.1/qmetatype.html#qRegisterMetaType) makes sense to you, but that seems to be related to the error.
@karensantana Also, if that doesn't work, you could try asking a new question - there are loads of smart people around here and somebody is bound to be a Qt expert :) Good luck with everything!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.