24 June 2019 at 19 h 54 min #13853
Does anyone have experience running multithreading in Python. I tried to add the following
and this gives a bunch of errors as
[ERROR] [ExecParams] [THREAD 2]: invalid ExecParams used, belonging to thread 3
[ERROR] [MechanicalObject(spring)] Invalid vOp operation 1 (null(V_DERIV),0(0),0(0),1)
From the .scn examples, it didn’t seem like additional setup was necessary to run multithreaded, but is there something different to do in Python?
Jie Ying28 June 2019 at 12 h 24 min #13867HugoKeymaster
28 June 2019 at 18 h 39 min #13869jnbrunetParticipant
- SOFA Consortium
- MIMESIS team, INRIA
Are you sure it is a python-related error? The same scene with a .scn file works?7 July 2019 at 18 h 10 min #13915
Yes – I simplified my scene so it’s only two objects, and now it shows a different error. Adding the DataExchange line breaks the simulation in Python, with the error that it is invalid syntax, but the same scene does what I’d expect as a .scn file.
rootNode.createObject('DataExchange', name='exchangeData1', template='vector<float>', from='@FloorScene/Floor/mecha.position', to='@CylinderScene/Cylinder/Cyl.position')9 July 2019 at 16 h 26 min #13921HugoKeymaster
- SOFA Consortium
Could you share with us your full scene file please?
Hugo9 July 2019 at 16 h 40 min #13923
My messages to post full scenes keeps on being flagged as spam but I’ve uploaded my code to https://github.com/JieYingWu/sofa_dvrk/blob/master/multithread.py and the scene file i s at the corresponding https://github.com/JieYingWu/sofa_dvrk/blob/master/multithread.scn.
Jie Ying16 December 2019 at 7 h 18 min #14696walemarkParticipant
The Python Global Interpreter Lock or GIL, in simple words, is a mutex (or a lock) that allows only one thread to hold the control of the Python interpreter. All the GIL does is make sure only one thread is executing Python code at a time; control still switches between threads. What the GIL prevents then, is making use of more than one CPU core or separate CPUs to run threads in parallel.
Python threading is great for creating a responsive GUI, or for handling multiple short web requests where I/O is the bottleneck more than the Python code. It is not suitable for parallelizing computationally intensive Python code, stick to the multiprocessing module for such tasks or delegate to a dedicated external library. For actual parallelization in Python, you should use the multiprocessing module to fork multiple processes that execute in parallel (due to the global interpreter lock, Python threads provide interleaving, but they are in fact executed serially, not in parallel, and are only useful when interleaving I/O operations). However, threading is still an appropriate model if you want to run multiple I/O-bound tasks simultaneously.
- You must be logged in to reply to this topic.