Threading, in addons

Please post any questions about developing your plugin here. Please use the search function before posting!
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Threading, in addons

Postby Tuck » Mon Aug 20, 2012 8:11 pm

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
-Tuck
User avatar
Monday
Administrator
Posts: 98
Joined: Thu Jul 12, 2012 4:15 am

Postby Monday » Mon Aug 20, 2012 8:19 pm

Do imports keep running after you shut down idle? ;)
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Mon Aug 20, 2012 8:25 pm

uhg yea that make sense xD, any approach you would recommend? :)

What if i hold the unload event? until im done closing it :/
-Tuck
User avatar
Monday
Administrator
Posts: 98
Joined: Thu Jul 12, 2012 4:15 am

Postby Monday » Mon Aug 20, 2012 8:26 pm

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?
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Mon Aug 20, 2012 8:29 pm

they are both the "same addon" however they run in two different threads, so that i won't lag my main thread
-Tuck
User avatar
Monday
Administrator
Posts: 98
Joined: Thu Jul 12, 2012 4:15 am

Postby Monday » Mon Aug 20, 2012 10:11 pm

So why would it matter if you unloaded it?
your-name-here
Developer
Posts: 168
Joined: Sat Jul 07, 2012 1:58 am

Postby your-name-here » Tue Aug 21, 2012 12:38 am

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.
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Tue Aug 21, 2012 4:05 am

because it needs to close securly and finish it's queue and than safely close
-Tuck
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Aug 21, 2012 4:41 am

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
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Tue Aug 21, 2012 2:00 pm

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
-Tuck

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 28 guests