Hello @mfaraj57,
If you what to use python threading to make calculation or other staff that burden the processor then you should not do this because it will have effect as you described.
, because of GIL execution of your task will block execution of the python code from main enigma2 thread, so you will see spinner and so on.
If you want to make calculation or others time-consuming staff which burden the processo you have two possibilities:
1. Use separate process and made these calculation in separate process (second process np. python script should be executed with eConsoleApp)
2. Write module to python which will make all calculation in the C, if you need you can even create C thread (using pthread) which will not take GIL when not needed.
Here you can found good article which described On the restrictions associated with GIL:
https://opensource.c...e/17/4/grok-gil
may be the cause of abnormal behaviour by using GUI component through the thread but still need solution.
You should never use engiam2 components from different python threads because enigma2 components are not thread safety.
If you use twisted module then you can easy push some function from your thread to be executed in the context of the main thread.
To do this you can call reactor.callFromThread to delegate execution of function to main thread.
For example:
import threadingimport urllibimport urllib.requestimport timefrom twisted.internet import reactor def getTextLabel(url, callback): # becaouse of GIL you should not made a long # blocking operation in this thread # for example, this is OK # sleep will release GIL so main thread will not be blocked, sleep in this thread will not cause spinner time.sleep(100000) # this is NOT OK, such code will cause spinner agg = 0 for i in range(1000000): agg *= i for j in range(1000000): agg *= j for k in range(1000000): agg *= k # this is OK - connection will release GIL response = urllib.request.urlopen(url) html = response.read() # !!!!!!!!!!!!!!!!!!!!!! # you should NOT modify eLabel component from here # like that: # self["console"].setText(html) # you must delegate this task to main thread reactor.callFromThread(callback, html) def setTextToLabel(html): # this will be executed from main thread # so you can modify for example eLabel component from here self["console"].setText(html) def callInWorkThread(target, *args, **kwargs) thread = Thread = threading.Thread(target = target, name = target.Callable.__name__, args = args, kwargs = kwargs) thread = Thread.start() return thread def SomeMethodOfYourScreen(): # here we are in the main thread callInWorkThread(target = getTextLabel, 'http://python.org/', setTextToLabel)
Thanks samsamsam
The informations and ideas looks interesting,hope get some time to apply and see.
I do not want to go deep before examining the code but using twisted has problems with some secure links as i put thread in this forum in the past but i do not have the link now.
Econsoleapp is very slow with time consuming processes.
However i am using threading now to process the host module and to get the data without problem,i bypassed the behavior problem mentioned above by showing gui component by using etimer from the opened thread.
Edited by mfaraj57, 23 September 2018 - 21:14.