1

I have a genetic expression tree program to control a bot. I have a GP.py and a MyBot.py. I need to be able to have the MyBot.py access an object created in GP.py

The GP.py is starting the MyBot.py via the os.system() command

I have hundreds of tree objects in the GP.py file and the MyBot.py needs to evaluate them.

I can't combine the two into one .py file because a fresh instance of MyBot.py is executed thousands of times, but GP.py needs to evaluate the fitness of MyBot.py with each tree.

I know how to import the methods and Class definitions using import GP.py, but I need the specific instance of the Tree class object Any ideas how to send this tree from the first instance to the second?

1
  • Is there a spesific reason to use os.system()? My first choice would be to run MyBot in a thread. Commented Dec 14, 2011 at 7:05

3 Answers 3

2

You could serialize the object with the pickle module (or maybe json?)

If you really want to stick with os.system, then you could have MyBot.py write the pickled object to a file, which GP.py could read once MyBot.py returns.

If you use the subprocess module instead, then you could have MyBot.py write the pickled object to stdout, and GP.py could read it over the pipe.

If you use the multiprocessing module, then you could spawn the MyBot process and pass data back and forth over a Queue instance.

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

Comments

0

Usually in such cases RPC is used. In python i usually use XML-RPC:

http://docs.python.org/library/simplexmlrpcserver.html

http://twistedmatrix.com/documents/current/web/howto/xmlrpc.html

This is a more flexible solution than passing data via files, and works even if the processes are on different machines.

Comments

0

We are developing an ORB interaction framework Versile Python (AGPL) which can be used for such inter-process object-level communication. It is in development but you may want to have a look. This recipe shows how you could use pipes between GP.py and MyBot.py to access remote objects. You can use the link with native python objects to get direct access to python objects, or write custom external objects.

Comments

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.