Page 1 of 1

Threading, in addons

Posted: Mon Aug 20, 2012 8:11 pm
by Tuck
Is it suppose to terminate all threads a addon created on sp_unload ?, i have a thread where i need to safely close it and it works as intended in IDLE but true SP it just terminates the hole thing when the main script gets unloaded my thread is imported from another .py file, just incase that matters

(Or maybe this is just how python works, since i don't import my sub script as i do in idle because SP wont allow me)

Syntax: Select all

from <addon> import sql


(where in idle i just simple do)

Syntax: Select all

import sql

Posted: Mon Aug 20, 2012 8:19 pm
by Monday
Do imports keep running after you shut down idle? ;)

Posted: Mon Aug 20, 2012 8:25 pm
by Tuck
uhg yea that make sense xD, any approach you would recommend? :)

What if i hold the unload event? until im done closing it :/

Posted: Mon Aug 20, 2012 8:26 pm
by Monday
Tuck wrote:uhg yea that make sense xD, any approach you would recommend? :)


Why are you running 2 seperate addons that need to be loaded/unloaded?

Posted: Mon Aug 20, 2012 8:29 pm
by Tuck
they are both the "same addon" however they run in two different threads, so that i won't lag my main thread

Posted: Mon Aug 20, 2012 10:11 pm
by Monday
So why would it matter if you unloaded it?

Posted: Tue Aug 21, 2012 12:38 am
by your-name-here
Tuck wrote:Is it suppose to terminate all threads a addon created on sp_unload ?, i have a thread where i need to safely close it and it works as intended in IDLE but true SP it just terminates the hole thing when the main script gets unloaded my thread is imported from another .py file, just incase that matters

(Or maybe this is just how python works, since i don't import my sub script as i do in idle because SP wont allow me)

Syntax: Select all

from <addon> import sql


(where in idle i just simple do)

Syntax: Select all

import sql


Just as an FYI: IDLE is not a good test bed for your code because its not embedded into a process.

Posted: Tue Aug 21, 2012 4:05 am
by Tuck
because it needs to close securly and finish it's queue and than safely close

Posted: Tue Aug 21, 2012 4:41 am
by satoon101
Unloading a script unloads all modules within the scripts structure as well. We have designed Source.Python that way for a reason. This allows scripts (and their modules) to be updated, and when re-loaded, update properly by being re-imported.

I guess overall, I am not really sure why you are using threading. I'm not very well versed in sqlite3, but I "think" it still handles all requests (commit, close, etc...) you pass it, even if the functions that call it are now out of scope. I don't understand why, instead of calling commit and close natively, you decide to use global variables and threading (and a very noisy while statement) to accomplish this. Maybe I'm wrong, but there has to be a much better way to do this.

If not, the only way around this would be to place your sql module outside of your script's structure.

Satoon

Posted: Tue Aug 21, 2012 2:00 pm
by Tuck
The other way would be opening and closing database all the time or running it in main and let it lag the server >_>

But i figured out how to go around it calling some code on unload event in the main addon that would than tell module to close via the main thread