I have the application where user presses button (Multiple buttons for different directory) and the timer function will be called. When the timer is complete, another function will be called and it will look for the file on directory. If the file exists, it will grab the information otherwise it will call the timer function again.
Now, the different button will look for the different file, however, the button could be pressed simultaneously. I am afraid that if the function is called and the timer is running than calling the same function again will make it complicated.
I tried looking for multi threading but since I am still a beginner, i couldn’t understand.
The Script in Script Library [Project] -
The error about the timerFunc taking 1 argument is due to leaving out the self argument of the function. In order to call timerFunc from an instance of the PullingData class as you are doing, you simply need to change the function definition to include self:
to define a method in Python you use the following syntax.
def methode_name(self, [args]):
in your script, the self-argument is "Machine". Because you can name it in python the way you like, the behavior of the functions does not expect, an argument.
So your method definitions should be: def timerFunc(self, Machine):
I have not analyzed the code so I do not know if the code works. But this is the cause of the error
looks to me like timerFunc never returns a value, my guess is you will experience a UI freeze if you are executing this code from a button press without the use of invokeLater.
I’m not sure I understand exactly what the goal of the program is, perhaps there is a better way to accomplish your task than ‘multi-threading’ (which I see no evidence you are actually doing) in the UI thread.
The __init__ function should always return None. In this case, that will work since it just so happens that timerFunc returns None, but it is best to leave out the return statement for __init__. You could try putting in print statements at various points to see what is getting executed.
Also, it looks like you could accomplish this more simply by using the ‘Timer’ Vision component.