Question

A quick question for Python 2.7

Are global variables visible to a subprocess?

Can a subprocess change the values of global variables?

Many thanks.

Was it helpful?

Solution 2

The processes doesn't share the variables in a general operating system terms. Use some communication mechanism like message passing, shared memory etc to achieve the inter process communication.

OTHER TIPS

No, global variables are not visible to a sub-process. Variables are private to each process. If you want to share variables then you need to use some form of inter-process communication.

Maybe the simplest way is write those into a file and read from the file in another process, although this might take extra time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top