AttributeError: pyrna_struct_meta_idprop_setattro() can't set in readonly state

This print screen shows a part of my code that is having a problem:


When you run these lines, is displayed this message:


Exception in thread Thread-6:
Traceback (most recent call last):
  File "...\2.74\python\lib	hreading.py", line 921, in _bootstrap_inner
    self.run()
  File "...\2.74\python\lib	hreading.py", line 869, in run
    self._target(*self._args, **self._kwargs)
  File "...Bleder.blend\mano_music_player", line 50, in soundIsOn
AttributeError: pyrna_struct_meta_idprop_setattro() can't set in readonly state 'WindowManager.mano_music_timeline'

Does anyone know what this means?
The problem is this line (50):
“bpy.types.WindowManager.mano_music_timeline = bpy.props.IntProperty(min = 0, max = round(duration), subtype = ‘FACTOR’)”

One thing that jumps out at me is that you are trying to change bpy.types.WindowManager

“bpy.types.WindowManager” is a variable/attribute of the bpy.types module, it is a Python object, and theoretically the Python syntax lets you modify attributes on it. BUT it’s actually a class from which instances are created.

What you may actually want to use is bpy.context.window_manager. Without running that code in your blend file I can’t say if that is the solution, but it may be a step forward. In case the context is inaccessible, try bpy.data.window_managers[0]

Thank you @Bayesian. With bpy.context.window_manager and bpy.data.window_managers[0] I can change the current value of the property, but I can’t change its maximum value :(.

That’s what I’m trying to do with the line:
“bpy.types.WindowManager.mano_music_timeline = bpy.props.IntProperty(min = 0, max = round(duration), subtype = ‘FACTOR’)”

Sometimes it works and sometimes not. Who wants to test the script is here.

Attachments

mano_music_player.zip (9.64 KB)

It might look strange to you, but that code is actually correct. This is how you define new properties on Blender ID types (such as Object, Mesh, but also WindowManager).

The error seems to occur because you’re trying to access Blender data from another thread. Don’t do that, it can crash Blender. See API Gotchas.

Sorry, I probably misunderstood the intentions of the script…

Yes, you’re right. But Blender doesn’t crash with the script (it seems stable). The problem is the error message (it stop script execution).

In fact there is a crash. But only after you close Blender. It must be the problem “sys.exit” Mentioned on the site. I will solve this later.

But has to have a way to solve the current problem. [SUB](Example: Using “try:” and if “except:” try again until it works. (bad solution))[/SUB]

I could summarize the bug script:


import bpy
import threading
import time


bpy.types.Scene.test_bug = bpy.props.IntProperty(max = 0)
def function_in_Thread(max):
    time.sleep(2)
    bpy.types.Scene.test_bug = bpy.props.IntProperty(max = max)
    print(bpy.types.Scene.test_bug[1])


Thread = threading.Thread(target=function_in_Thread, args = (5,))
Thread.start()

Try resizing some area during the 2 seconds after running the script. This increases the error probability.

Thanks @BeerBaron for the help. I’ll take a look at this module (asyncio).