Multithreaded Python

Discussions concerning programming of SOFTIMAGE©
User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 14:00

Multithreaded Python

Post by TwinSnakes007 » 21 Sep 2012, 18:48

So, I'm writing this script to export particles from SI in Python, and its performing well using that ProjectItem.EvaluateAt() method to export the animation.

But, my tests where with < 1000 particles. Is there a way to multithread a python script so I can spread the work out across processors?

-TS-

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 09:02
Location: Montreal Canada

Re: Multithreaded Python

Post by xsisupport » 21 Sep 2012, 19:17

TwinSnakes007 wrote:So, I'm writing this script to export particles from SI in Python, and its performing well using that ProjectItem.EvaluateAt() method to export the animation.

But, my tests where with < 1000 particles. Is there a way to multithread a python script so I can spread the work out across processors?

-TS-
Well, if you end up with a multithreaded plugin, you should not be calling the Softimage SDK from your worker threads. The SDK isn't multithreaded.
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

luceric
Posts: 1252
Joined: 21 Jun 2009, 22:08

Re: Multithreaded Python

Post by luceric » 21 Sep 2012, 19:58

Although python support threads, the interpreter only runs one at at time. So you can't even gain much with threads.

User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 14:00

Re: Multithreaded Python

Post by TwinSnakes007 » 21 Sep 2012, 20:15

C++ is not an option. Would I see some multithreaded gains if I script in C#?

-TS-

luceric
Posts: 1252
Joined: 21 Jun 2009, 22:08

Re: Multithreaded Python

Post by luceric » 21 Sep 2012, 20:30

well you can't ask XSI to evaluate in multiple threads.
have you tried caching out the particles, but then writing a script that reads the cache file instead? there is a code on the web for reading ICEcache in python
http://bilzlee.blogspot.ca/
http://code.google.com/p/ice-cache-explorer

User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 14:00

Re: Multithreaded Python

Post by TwinSnakes007 » 21 Sep 2012, 20:56

luceric wrote:have you tried caching out the particles, but then writing a script that reads the cache file instead?
Yeah, I knew about the python ICECache reader and that's still an option.
luceric wrote:well you can't ask XSI to evaluate in multiple threads.
What does that mean? Does it mean this pseudo code would not work?

Code: Select all

Thread 1
Array = SIObject.ICEAttribute.GetDataArrayChunk(0, 1000);

Thead 2
Array = SIObject.ICEAttribute.GetDataArrayChunk(1001, 2000);

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 09:02
Location: Montreal Canada

Re: Multithreaded Python

Post by xsisupport » 22 Sep 2012, 10:37

You cannot call the SDK from different worker threads.
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 14:00

Re: Multithreaded Python

Post by TwinSnakes007 » 22 Sep 2012, 17:47

xsisupport wrote:You cannot call the SDK from different worker threads.
Oh, okay, it finally clicked after reading some more docs.

....I found this is some example code
XSI SDK wrote:Calling Softimage operations from worker threads may put Softimage in an undefined state.
So, they recommend using an event callback in the main thread.

For anyone else that's learning like me...look at the XSIServer.cs and XSIServiceProvider.cs files in the SDK for a demo.

-TS-

User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 14:00

Re: Multithreaded Python

Post by TwinSnakes007 » 30 Sep 2012, 03:25

The C# SDK is faaaast. I really like the speed I'm seeing, I wrote about 5k particles in XML format out to the file system and it was instant. [position, scale, color, shape, rotation attributes].

:ymapplause: