For example:
Syntax: Select all
# global
_G:dict
# plugin1.py
tmp = _G.copy()
tmp['test'] = 0xDEED
_G.update(tmp)
# plugin2.py
print(_G.get('test', None))
Syntax: Select all
# global
_G:dict
# plugin1.py
tmp = _G.copy()
tmp['test'] = 0xDEED
_G.update(tmp)
# plugin2.py
print(_G.get('test', None))
Syntax: Select all
from plugin1 import plugin1
print(plugin1.tmp)
Syntax: Select all
# plugin1.py
from threading import Thread
from time import sleep
def set():
sleep(5)
_G['test_var1'] = 288
th = Thread(target=set)
th.daemon = True
th.start()
Syntax: Select all
# plugin2.py
from threading import Thread
from time import sleep
def get():
while True:
print('[i] test_var1 -> {}'.format(_G.get('test_var1', 0))
sleep(1)
th = Thread(target=get)
th.daemon = True
th.start()
Sam wrote:You do not understand me. I would like to implement `globals()` for everything.
When executing the plugin, I cannot interact with `dict` from outside the plugin environment.
Syntax: Select all
# plugin1.py
from threading import Thread
from time import sleep
from mypackage import _G
def set():
sleep(5)
_G['test_var1'] = 288
th = Thread(target=set)
th.daemon = True
th.start()
Syntax: Select all
# plugin2.py
from threading import Thread
from time import sleep
from mypackage import _G
def get():
while True:
print('[i] test_var1 -> {}'.format(_G.get('test_var1', 0)))
sleep(1)
th = Thread(target=get)
th.daemon = True
th.start()
Syntax: Select all
# ../addons/source-python/packages/custom/mypackage.py
_G = dict()
Code: Select all
sp plugin load plugin1;sp plugin load plugin2
[SP] Loading plugin 'plugin1'...
[SP] Successfully loaded plugin 'plugin1'.
[SP] Loading plugin 'plugin2'...
[i] test_var1 -> 0
[SP] Successfully loaded plugin 'plugin2'.
[i] test_var1 -> 0
[i] test_var1 -> 0
[i] test_var1 -> 0
[i] test_var1 -> 0
[i] test_var1 -> 288
[i] test_var1 -> 288
[i] test_var1 -> 288
[i] test_var1 -> 288
Return to “General Discussion”
Users browsing this forum: No registered users and 107 guests