Indeed, my guess is that you get this error after you stopped the game and waited a bit, am I right?
I don’t really understand what you mean by “above BGE’s ticks”. One thing for sure, things can happen outside of the ticks. Just look at any process on your computer: they don’t stop, waiting for your Python script to finish.
Indeed, it is a per-thread singleton if I remember correctly (maybe read that in some doc… not sure)
Python modules being imported once is only an effect of the Python import system caching module queries. Say you do import abc
for the first time, it will first look inside the dictionnary sys.modules
for a key named abc
: if it doesn’t exists, actually parse and import the file from disk/whatever, and add the entry to sys.modules
. Next time it will look up inside the dictionnary, sys.module['abc'] = <module abc>
is already defined, so use that instead of re-importing everything.
Also pouring your own data inside third-party modules is a very bad practice
Why not making your own module file and do that there? Anyway.
Well, I thought I would need a dedicated server too, turns out that some free hosting services actually do the trick, see Heroku, am pretty happy with it, even though it is not direct TCP/UDP.
Thinking back on your “stuff happens between ticks”, yes, things can exist outside of one tick.
A game logic tick is merely just the point where the full Blender Player application comes inside the part of its mainloop where it will call every script that needs to be called.
Because your script is only part of one iteration, you might feel like you are “stuck inside one tick”, but that’s only the BGE that makes you think that, and the way we interact with it.
Bit of advice to break out of this: Define your own singletons or whatever, and either use Python Components, or Python Modules (still using Logic Bricks).
Python Modules have the advantage of executing the function of a module, which means that your file main body will be executed only once, but your function will be triggered on each tick. You will be able to store global states like this, and finally be “out of the ticks”
To be fair the way logic must be defined in the BGE always bothered me, and I’ve been looking at a lot of different solutions. The way I am doing it for this game seems to the best I found so far, in my opinion of course. Maybe some things to improve, but oh well