0

I'm using a module named spynner with python. spynner runs on a QApplication instance. I need to run functions using spynner asynchronously.

I have tried calling these functions in different threads, using something like: thread.start_new_thread(function_using_spynner)

This works if I run just one function, but if I try to run 2 of them I get an error saying that QApplication can not be created outside of main thread. Is there a way to run functions asynchronously in the same thread? The functions return nothing, so just running them will be enough.

If not, is there a workaround for creating QApplication instances outside of main thread? I don't need a display.

Ozgur Akcali
  • 5,264
  • 2
  • 31
  • 49

1 Answers1

0

You could run function_using_spynner in the main thread and do whatever else you need to do in the other thread. Alternatively, you could start the QApplication in spynner in the main thread before branching into multiple threads.

Benjamin Peterson
  • 19,297
  • 6
  • 32
  • 39
  • But in my case, I need to run three such functions simultaneously, so I need to run two of them in other threads. And about the latter, I've tried that, but that also causes several Qt specific problems, like: QObjest's parent must be in the same thread, can not create a child in another thread. – Ozgur Akcali Aug 10 '11 at 13:15
  • I don't think you'll be able to do this using threads. Maybe you could run several processes instead? – Dan Milburn Aug 10 '11 at 20:15
  • What will be the difference between running them in threads and processes? – Ozgur Akcali Aug 11 '11 at 00:27
  • @OzgurAkcali, Threads are essentially the same thing as processes EXCEPT they operate in the same memory space. Processes exist in their own memory space. Also, python threads don't take advantage of multicore processesors. Threads are lighter in terms of memory consumption though. – kylex Aug 15 '13 at 01:37