[SOLVED] Jython jsr223 not properly initialised during startup


I’m still fighting with some problems I have during my openhab startup.

If I start openhab I can see a error message like that

Error during evaluation of script 'file:/dataDisk/openhab-runtime/conf/automation/jsr223/auto.py': TypeError: can't set attributes of built-in/extension type 'NoneType' in <script> at line number 3

this line contains my first import statement.

If I wait 1-3 minutes and touch this file again, everything works fine. For me this looks like, that something is not ready and the python initialization comes to early.

The reason for my guess is, because I had also trouble with javascript. I was loaded before e.g. the automationManager was available. So it was crashing during startup too and only a late touch helps. I switched to python because I was hoping it works better here. But it doesn’t

@Kai explained some times ago that in openhab everything is loaded asynchronous. That fine, but if some root dependencies are not available it can’t be the answer or solution. It can’t be handled in a good way. Or what is the official recommendation for that.

Just a side fact. I’m running my openhab on a Intel atom processor with hundreds of items. So the startup really takes a while. Mostly more then 2 minutes. During this time all 4 cores are at 100%

and I’m using openhab 2.3

I debugged it a little bit more. I created a almost empty test.py file with just 2 line

import java.util
from openhab.rules import rule

and now I get this error message during startup

Error during evaluation of script 'file:/dataDisk/openhab-runtime/conf/automation/jsr223/test.py': TypeError: can't set attributes of built-in/extension type 'NoneType' in <script> at line number 2

I guess the module “rules.py” in my module folder “openhab” is not loaded and initialized yet. If i “touch” my “test.py” file 2 minutes later, it is loaded fine.

I think I found the reason.

It is an error in an external module and this is related to the early startup of scripts before the openhab scope is fully initialized.

  • the first problem I see here are the error logs. There is no way to show module errors. Just this “useless” message of the final import statement.

  • second problem is the not initialized scope. In my case I use the openhab modules provided by the Jython Scripters project. Inside this module is the _init_.py file. This is trying to access the global item registry from the current scope. But I debugged it with Logger calls and during this early startup this item registry is None with the result that the whole openhab module is not working.
    2 minutes later, if I touch all files again. It is not None and everything works fine.

  • third problem. I don’t know where to create a bug report. There are so many github openhab projects that I’m everytime confused where is the right place to create an issues.

@steve1 some month ago the jython scripters project itself had also an issues tracker but for some reason this is disabled.

JSR223 is functionality provided by Eclipse SmartHome. So you can use the ESH issue tracker for this. It also contains other JSR223 initialization issues such as ESH #4324.

thanks for the hint. I added my comment to this ticket.

Yesterday evening, I implemented a workaround. Inside ESH #4324 I got the hint for a workaround. They created a script which is loading first and is sleeping for a specific amount of seconds. This will postpone the initialization of all other jsr223 scripts. For me this is not enough, because it is difficult to now the exact time when everything is initialized. So I extended the script a little bit.

Now my script is checking every 10 seconds if the automationManager is available. It not it is waiting for additional 10 seconds and then checks again. If the automationManager is initialized, it will continue. So all other scripts are loaded without any problem. The script name has to start with ‘000_’. Otherwise it will not loaded as the first script.

my script “000_burntime.py” look like this.

import time

from org.slf4j import Logger, LoggerFactory

log = LoggerFactory.getLogger("org.eclipse.smarthome.automation")

log.info("jsr223: checking for initialised context")

while True:
        if automationManager != None:
    log.info("jsr223: context not initialised yet. waiting 10 sec before checking again")

log.info("jsr223: done")

Thanks! I finally got it to work using your script.

It is important to note though that you must have at least one item defined. If you do not have any items defined (e.g. you’re using a maiden openHAB install), then the automationManager will quickly no longer be None and the script continues. However your own scripts will then still fail at the import openhab

line with a

TypeError: can't set attributes of built-in/extension type 'NoneType' in <script> at line number


Your script really should be part of the openhab2-jython and lucid repositories. To be sure I would prefix it with another 0 though so that it will always be loaded first, even if someone comes up with a 000_a<something>.py script.

(Tested on openHAB 2.4.0 Snapshot Build #1362)

1 Like

And if which directory is this script put into, please?

copy it into the same directory as your other jython scripts

@holger_hees Thank you! I’ve been scratching my head for a while on this.
@5iver Could we document this at the very beginning of the open-jython project? Thanks.

A startup delay script and a note in the Quick Start Guide has already been included in PR #41.