H3D.org Forum Index Programming Issues
Python threads | Register To Post |
| Threaded | Newest First | Previous Topic | Next Topic | Bottom |
| Poster | Thread |
|---|---|
| jofo | Posted on: 2012/1/21 8:59 |
Quite a regular ![]() ![]() Joined: 2007/1/8 From: Stockholm Posts: 38 |
Python threads I'm trying to spawn a thread from a python script (initiated from x3d file), but it runs terrible slow. My goal is to launch a simple web server to feed data to/from the nodes...
Even if I run a simple thread printing hello world every second it seems stocastic if it will print anything at all. It works find stand-alone python. Any suggestions? H3D 2.1, Linux 32bit.
from H3D import *
|
| Markus | Posted on: 2012/1/23 16:36 |
Webmaster ![]() ![]() Joined: 2006/3/27 From: SenseGraphics Posts: 1903 |
Re: Python threads Daniel updated something with threads and python during the summer so try with trunk and maybe it will go faster.
|
| karlu | Posted on: 2012/1/23 20:57 |
Guru ![]() ![]() Joined: 2004/12/2 From: Sweden Posts: 758 |
Re: Python threads My experience is that the Python thread is only running when the H3D program is running the Python script. I had to add an auto update with a pause to make it run smoothly:
class App(threading.Thread):
|
| daniel | Posted on: 2012/1/26 21:18 |
Webmaster ![]() ![]() Joined: 2004/11/28 From: Posts: 536 |
Re: Python threads The underlying problem is that Python threads do not actually run concurrently. Instead only one Python thread runs at any time and Python will determine which thread that runs. Normally a certain number of instructions must be executed in one thread before the next thread is allowed to run the same number of instructions and so on. Because of this the behaviour that karlu mentions(that one has to run Python code from H3D in order for other threads to run as well). In the current development version this is not needed since H3D will explicitly release a global Python lock when not executing in order for other threads to run. If you still have problems with the dev version, please post a bug report.
|
| jofo | Posted on: 2012/2/1 20:19 |
Quite a regular ![]() ![]() Joined: 2007/1/8 From: Stockholm Posts: 38 |
Re: Python threads Hi, thanks, it works well with trunk. Even with the webserver :)
Just a note on compiling it as of yesterday: include/H3D/CoordinateDeformer.h need #include <H3D/SFString.h> then H3DSingleTextureNode.h is not installed to /usr/local/include/H3D automatically. unfortunately my full application gives segfault w trunk, but thats a separate issue. |
| Markus | Posted on: 2012/2/2 8:25 |
Webmaster ![]() ![]() Joined: 2006/3/27 From: SenseGraphics Posts: 1903 |
Re: Python threads Issues fixed (one of them I had already fixed but not checked in).
If you ever build on Windows again, consider using the cmake option GENERATE_UNITY_BUILD, makes things go a bit faster (but will be the cause of some include files missing in some headers sometimes). |
| Threaded | Newest First | Previous Topic | Next Topic | Top |
| Register To Post | |





