Hello
In an addon I would like to start a modal timer operator (to read a device) as soon Blender is started.
Unfortunately I’m stuck, the operator seems extremely picky about the context.
I tried various things but so far getting only errors and segfaults:
- putting the operator call straight in the register function -> error :
scene = context.scene
AttributeError: '_RestrictContext' object has no attribute 'scene'
- via a “load_post” handler in the register function -> segfault
I don’t know if it is helpful but here is the backtrace:
$ cat /tmp/blender.crash.txt
# Blender 2.70 (sub 0), Commit date: 1970-01-01 00:00, Hash unknown
# backtrace
blender() [0x9730ad]
/lib64/libpthread.so.0(+0x10b10) [0x7f972da37b10]
blender(BLI_addhead+0x5) [0x10b87e5]
blender(WM_event_add_modal_handler+0x80) [0x97c2f0]
blender(WindowManager_modal_handler_add_call+0xc) [0x150f86c]
blender(RNA_function_call+0x12) [0x141ecb2]
blender() [0xd00259]
/usr/lib64/libpython3.3.so.1.0(PyObject_Call+0x7a) [0x7f972e99c45a]
/usr/lib64/libpython3.3.so.1.0(PyEval_EvalFrameEx+0x31dc) [0x7f972ea45dfc]
/usr/lib64/libpython3.3.so.1.0(PyEval_EvalCodeEx+0x803) [0x7f972ea4aad3]
/usr/lib64/libpython3.3.so.1.0(+0x87c8f) [0x7f972e9c2c8f]
/usr/lib64/libpython3.3.so.1.0(PyObject_Call+0x7a) [0x7f972e99c45a]
blender() [0xd00ed4]
blender() [0x150f0a3]
blender() [0x979aaa]
blender(WM_operator_call_py+0x6f) [0x97a38f]
blender() [0xd0a06c]
/usr/lib64/libpython3.3.so.1.0(PyEval_EvalFrameEx+0x649f) [0x7f972ea490bf]
/usr/lib64/libpython3.3.so.1.0(PyEval_EvalCodeEx+0x803) [0x7f972ea4aad3]
/usr/lib64/libpython3.3.so.1.0(+0x87c8f) [0x7f972e9c2c8f]
/usr/lib64/libpython3.3.so.1.0(PyObject_Call+0x7a) [0x7f972e99c45a]
/usr/lib64/libpython3.3.so.1.0(+0x74e0d) [0x7f972e9afe0d]
/usr/lib64/libpython3.3.so.1.0(PyObject_Call+0x7a) [0x7f972e99c45a]
/usr/lib64/libpython3.3.so.1.0(+0xb3f6b) [0x7f972e9eef6b]
/usr/lib64/libpython3.3.so.1.0(PyObject_Call+0x7a) [0x7f972e99c45a]
/usr/lib64/libpython3.3.so.1.0(PyEval_EvalFrameEx+0x31dc) [0x7f972ea45dfc]
/usr/lib64/libpython3.3.so.1.0(PyEval_EvalCodeEx+0x803) [0x7f972ea4aad3]
/usr/lib64/libpython3.3.so.1.0(+0x87c8f) [0x7f972e9c2c8f]
/usr/lib64/libpython3.3.so.1.0(PyObject_Call+0x7a) [0x7f972e99c45a]
blender(bpy_app_generic_callback+0x8c) [0xd0778c]
blender(BLI_callback_exec+0x2d) [0x10b2abd]
blender(main+0xbd7) [0x95ef97]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f97296c3c45]
blender() [0x971c35]
- via a thread with a timer set to 5 second to defer the call -> segfault
Weird because the default scene is loaded and the context should be ok (??).
Here is the backtrace as well, almost the same output:
$ cat /tmp/blender.crash.txt
# Blender 2.70 (sub 0), Commit date: 1970-01-01 00:00, Hash unknown
# backtrace
blender() [0x9730ad]
/lib64/libpthread.so.0(+0x10b10) [0x7f38edde0b10]
blender(BLI_addhead+0x5) [0x10b87e5]
blender(WM_event_add_modal_handler+0x80) [0x97c2f0]
blender(WindowManager_modal_handler_add_call+0xc) [0x150f86c]
blender(RNA_function_call+0x12) [0x141ecb2]
blender() [0xd00259]
/usr/lib64/libpython3.3.so.1.0(PyObject_Call+0x7a) [0x7f38eed4545a]
/usr/lib64/libpython3.3.so.1.0(PyEval_EvalFrameEx+0x31dc) [0x7f38eedeedfc]
/usr/lib64/libpython3.3.so.1.0(PyEval_EvalCodeEx+0x803) [0x7f38eedf3ad3]
/usr/lib64/libpython3.3.so.1.0(+0x87c8f) [0x7f38eed6bc8f]
/usr/lib64/libpython3.3.so.1.0(PyObject_Call+0x7a) [0x7f38eed4545a]
blender() [0xd00ed4]
blender() [0x150f0a3]
blender() [0x979aaa]
blender(WM_operator_call_py+0x6f) [0x97a38f]
blender() [0xd0a06c]
/usr/lib64/libpython3.3.so.1.0(PyEval_EvalFrameEx+0x649f) [0x7f38eedf20bf]
/usr/lib64/libpython3.3.so.1.0(PyEval_EvalCodeEx+0x803) [0x7f38eedf3ad3]
/usr/lib64/libpython3.3.so.1.0(+0x87db0) [0x7f38eed6bdb0]
/usr/lib64/libpython3.3.so.1.0(PyObject_Call+0x7a) [0x7f38eed4545a]
/usr/lib64/libpython3.3.so.1.0(+0x74e0d) [0x7f38eed58e0d]
/usr/lib64/libpython3.3.so.1.0(PyObject_Call+0x7a) [0x7f38eed4545a]
/usr/lib64/libpython3.3.so.1.0(+0xb3f6b) [0x7f38eed97f6b]
/usr/lib64/libpython3.3.so.1.0(PyObject_Call+0x7a) [0x7f38eed4545a]
/usr/lib64/libpython3.3.so.1.0(PyEval_EvalFrameEx+0x2ffc) [0x7f38eedeec1c]
/usr/lib64/libpython3.3.so.1.0(PyEval_EvalFrameEx+0x61a2) [0x7f38eedf1dc2]
/usr/lib64/libpython3.3.so.1.0(PyEval_EvalFrameEx+0x61a2) [0x7f38eedf1dc2]
/usr/lib64/libpython3.3.so.1.0(PyEval_EvalCodeEx+0x803) [0x7f38eedf3ad3]
/usr/lib64/libpython3.3.so.1.0(+0x87c8f) [0x7f38eed6bc8f]
/usr/lib64/libpython3.3.so.1.0(PyObject_Call+0x7a) [0x7f38eed4545a]
/usr/lib64/libpython3.3.so.1.0(+0x74e0d) [0x7f38eed58e0d]
/usr/lib64/libpython3.3.so.1.0(PyObject_Call+0x7a) [0x7f38eed4545a]
/usr/lib64/libpython3.3.so.1.0(PyEval_CallObjectWithKeywords+0x47) [0x7f38eedeb957]
/usr/lib64/libpython3.3.so.1.0(+0x142062) [0x7f38eee26062]
/lib64/libpthread.so.0(+0x8f3a) [0x7f38eddd8f3a]
/lib64/libc.so.6(clone+0x6d) [0x7f38e9b35e8d]
I am a little short of new ideas and it is time to ask for some help.
You can find my test addon (which is basically the Modal Timer example found in the templates directory of the text editor) here:
http://www.pasteall.org/52374/python
(you can uncomment one of the 3 lines in the register function to see the 3 ways exposed and their respective pbms)