- 19/09/2019 at 09:35 #17149
i have wrote a multithreading program in PythonScript using “thread” module,but it shows a error dialog as follow:
the code as follow:
from vcScript import *
Does anyone know how to solve this problem?
Thanks for your help.019/09/2019 at 10:56 #17158
i think Multithreading is not supported in Python-Scripts of components…
Why do you need it?
Regards019/09/2019 at 11:01 #17153
I guess you’re using the module thread, which should not exposed to the user.
In normal CPython 2.7 it is a very low level implementation and should not be used (Python 2.7 aswell).
Here is an example from Stackless Python 2.7. This implementation of Python is used in VC. The usage differs a little bit. You can have “channels” which are a kind of message queue and schedulers.
Try as first if the provided examples are working.023/09/2019 at 03:41 #17232
I want to execute two parallel tasks in one python script,because the two tasks share the same resource .
Thanks for your reply,i will have a try.016/12/2019 at 19:51 #19323
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.0
You must be logged in to reply to this topic.