Multi-threading in PyTango
|
|
---|---|
Hi Community members, I am new to PyTango and exploring how multi-threading works in Python/PyTango. I want to do some processing in parallel when a command is invoked on the TANGO device. For this, I created a device server, with two spectrum attributes and one command. The command is executed to copy source spectrum attribute to the Target spectrum attribute, using two threads (each thread to change one element of the spectrum attribute) running in parallel. While the threads are running, "device timed out" error is observed which pauses working of the main device (ZMQ) thread and ATKPanel/Device server becomes unresponsive. After the custom thread's execution is completed, main ZMQ thread resumes and ATKPanel is able to reflect the changes. The test device code and error screenshot are attached to the post. Can anyone point me to a direction on how to resolve this issue? Is there any way to run threads in parallel without the main ZMQ thread being paused? Thanks & Regards, Apurva Patkar |
|
|
---|---|
I think this is a simple syntax problem: You are not running a separate thread, you are executing the function in the Thread() constructor statement. Instead, you want a reference to the function object, i.e. without parentheses. Console output when adding threading.current_thread() to print():
I changed your code to:
Output now:
No timeout on Jive device test window. In general, PyTango should be fully thread safe. Edit: Although PyTango is thread safe, you have to think about whether your end of the code could crash the program by changing data that is read from the main thread in the meantime (e.g. if array size changes you can get all sorts of crashes). You have to make your editing thread safe and for example make reading TargetAttr return a dummy value and AttributeQuality CHANGING. |
|
|
---|---|
Hi Leonard, Thank You for the prompt response. I made the changes in the code and now it is working fine. "device timed out" error is not occurring and the main device (ZMQ) thread is responding while the threads are running in parallel. Thanks & Regards, Apurva Patkar |