Closed untereiner closed 6 years ago
Hi @untereiner
I'm far from a python master, but thanks for the greeting ;) I don't know if static method can be binded directly. But I'm sure that if it is not possible you can create a static function that forward to the static method. So it should work...if you make a branch somewhere (or a PR with the WIP tag someone can probably help you to locate the problem).
We have a branch with our work on https://github.com/mimesis-inria/sofa/tree/wip_pythonAdvancedTimer We try to create a class which wrap the advanced timer and that can be binded using Python... without success so far.
Can static methods be binded ?
If your question is: "can c++ static methods be bound in python", then yes. If your question is "can I bind something as a python class/static method", I think the answer is yes but in any case you can wrap it as a free function in a module.
If applicable, I suggest your binding class follows the context protocol (https://www.python.org/dev/peps/pep-0343/) so that you can time code fragments using with
statements:
with Sofa.Timer('description'):
# do something time-consuming here
In this case, you need to:
beginStep
as the __enter__
methodendStep
as the __exit__
methodand that should be it.
+1 for the with statement.
Thank you for your comments! I will try to follow this pep. For now I created a class and bind the static functions of AdvancedTimer as free functions in this but I have an undefined reference at linking to the class I created `AdvancedTimer_PyTypeObject'
Should we close this issue @untereiner ?
If the issue is solved with the merge of the AdvnacedTimer branch. Could you close the issue.
To trace execution time I wanted to bind in python the advanced timer class to be able to retrieve it and interogate it during a simulation. (without using -c option of runSofa) I wanted also to change the format of the output. For now my binding does not work. Can static methods be binded ?
I think your are the python master @damienmarchal. Do you have any idea on how I can do ?
Suggested labels: