문제

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.

도움이 되었습니까?

해결책 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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top