1

My python script have weird behavior. So, I have python script A, which calls another script B many times. For calling B, I'm using subprocess module.

Snippets of script A:

for i in range(0,10000):
    parameters = []
    parameters.append("B")
    result = subprocess.call(parameters)

Snippets of script B:

testdata = some_logic
if testdata:
    function_1()
else:
    function_2()

So, script A will calls script B many times. After some tests, I noticed that variable testdata doesn't have expected value for current running script B. Is it somehow possible in running script B, that variable testdata has value from previous call B? What is scope for variable testdata in this case? Thanks for advice. Cheers

1
  • 1
    As a side note, you may want to change the title. mutliprocessing is a completely different module where (with a little effort), you can share state between processes. Commented Jan 18, 2013 at 15:45

1 Answer 1

4

subprocess.call starts a child process. That process knows nothing about what is going on in A or how many times it has been called -- All it knows is what commandline arguments you've passed to it. In this case, you're always calling 'B' with no commandline arguments since parameters always equals ['B'] when you call subprocess.call.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok. What will happen if I have more instances of script A running in same time?
Each instance of script A will spawn instances of script B -- All which know nothing of each other.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.