Eliminate all global state
-
- Posts: 10
- Joined: Tue Sep 20, 2016 10:17 pm
Eliminate all global state
Hey,
I work in the Animation/VFX as as software developer. I've been looking around for a scripting language I can embed in a hobby 3d tool I'm writing. Python is the industry standard scripting language for VFX at the moment, and is embedded into most tools and pipelines, but the abundant use of global variables in CPython and the GIL make it impractical to use as a scripting language for multi threaded vfx tools of the future. I came across Micro Python recently, and it looks like a fantastic project. I noticed just now that 'Eliminate all global state' was a wish list item for 2014. Was this ever achieved?
I work in the Animation/VFX as as software developer. I've been looking around for a scripting language I can embed in a hobby 3d tool I'm writing. Python is the industry standard scripting language for VFX at the moment, and is embedded into most tools and pipelines, but the abundant use of global variables in CPython and the GIL make it impractical to use as a scripting language for multi threaded vfx tools of the future. I came across Micro Python recently, and it looks like a fantastic project. I noticed just now that 'Eliminate all global state' was a wish list item for 2014. Was this ever achieved?
-
- Posts: 10
- Joined: Tue Sep 20, 2016 10:17 pm
Re: Eliminate all global state
I had a quick look through the source code and can see that there is still use of global variables. Does micropython have a GIL like CPython ?
Re: Eliminate all global state
Since MicroPython is single-threaded, it doesn't have a need for GIL. There is some ongoing work to add threads to it, and it may be necessary to add GIL with that (but I think so far it was avoided). However, I think MicroPython is not particularly easy to embed.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Eliminate all global state
@luke_titley Have you read this? http://forum.micropython.org/viewtopic. ... lit=thread As I understand it the _thread() module is supported on the WiPy but it's early days and there have been reports of problems.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 10
- Joined: Tue Sep 20, 2016 10:17 pm
Re: Eliminate all global state
Hey thanks for this. I'm mainly interested in having two completely independent instances of the interpreter running in separate threads managed by my application. Hence the questions about GIL and global variables. Probably the best bet is for me to trawl the forumn more and have a dig through the codebase. Thanks for the quick responses.
Sent from my HUAWEI VNS-L22 using Tapatalk
Sent from my HUAWEI VNS-L22 using Tapatalk
Re: Eliminate all global state
Most of the global state is stored in the _mp_state_vm_t struct
https://github.com/micropython/micropyt ... tate.h#L54
and the globals are retrieved using the MP_STATE_PORT macro.
https://github.com/micropython/micropyt ... #L222-L224
https://github.com/micropython/micropyt ... ort.h#L161
https://github.com/micropython/micropyt ... tate.h#L54
and the globals are retrieved using the MP_STATE_PORT macro.
https://github.com/micropython/micropyt ... #L222-L224
https://github.com/micropython/micropyt ... ort.h#L161
-
- Posts: 10
- Joined: Tue Sep 20, 2016 10:17 pm
Re: Eliminate all global state
Hi Dave.
That's awesome that you already have it all in that 'mp_state_ctx' struct. git grep tells me there's a little under 300 references to the 'MP_STATE_CTX', 'MP_STATE_VM' and 'MP_STATE_MEM'. I think it's just a case of ripping those out and passing the mp_state_ctx through to all the functions that need it. Or am I missing something ?
That's awesome that you already have it all in that 'mp_state_ctx' struct. git grep tells me there's a little under 300 references to the 'MP_STATE_CTX', 'MP_STATE_VM' and 'MP_STATE_MEM'. I think it's just a case of ripping those out and passing the mp_state_ctx through to all the functions that need it. Or am I missing something ?
-
- Posts: 10
- Joined: Tue Sep 20, 2016 10:17 pm
Re: Eliminate all global state
Looks like you've also got this 'mp_dynamic_compiler', which I guess would need to be moved out too. And mp_module___main__ which I guess is the '__main__' module.
Last edited by luke_titley on Wed Sep 21, 2016 8:59 pm, edited 1 time in total.
-
- Posts: 10
- Joined: Tue Sep 20, 2016 10:17 pm
Re: Eliminate all global state
Looks like you do have GIL as well, but if there can be one per interpreter then it's still fine.
Re: Eliminate all global state
I would probably just change the macro to get the pointer to the state context thru TLS (thread local storage) or something similar.luke_titley wrote:Hi Dave.
That's awesome that you already have it all in that 'mp_state_ctx' struct. git grep tells me there's a little under 300 references to the 'MP_STATE_CTX', 'MP_STATE_VM' and 'MP_STATE_MEM'. I think it's just a case of ripping those out and passing the mp_state_ctx through to all the functions that need it. Or am I missing something ?