3

I have two python programs. One is kind of data gathering program. The other is for analysis and prediction using Tensorflow.

(on Windows OS. python3.5. local )

The data gathering program requires 32-bit env because of API it is using. And as you know, the other program requires 64-bit env because of TensorFlow.

So

Q : I just need to send a dict data to TensorFlow and it sends one integer back as a return.

What is the most simple way to send data each other?

thanks for your time.

4
  • What is in the list you send? Integers? Commented Sep 9, 2017 at 7:44
  • @JohanL I mistaked. It is not list but dict. Items are all integers. Commented Sep 9, 2017 at 7:48
  • 2
    The easiest is probably serializing the data (json / csv / pickle / whatever) and dumping it to a standard file on one hand, and reading the file and deserializing it on the other. You could also explore more efficient solutions like sockets or shared memory. Commented Sep 9, 2017 at 7:49
  • 2
    @jedwards I agree but there might be an issue with continuous data, to synchronize writes and reads. A slightly more complex solution would be to send the serialized data over a pipe (if that is available between 32 and 64 bit processes in Windows?) or through a socket. That still requires some kind of protocol to ensure all data is passed, though. Commented Sep 9, 2017 at 7:53

2 Answers 2

2

The simplest way would be to have one program save the data into a file, and then have the other program read the file. The recommended way to do this is to use JSON, via the json module.

import json

#Write
with open('file.txt', 'w') as file:
    file.write(json.dumps(myDict))

#Read
with open('file.txt') as file:
    myDict = json.load(json_data)

However, depending on your use case, it might not be the best way. Sockets are a common solution. Managers are also very robust, but are overkill in my opinion.

For more information, I recommend checking out the list that the Python team maintains, of mechanisms that you can use for communication between processes.

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

Comments

1

If you want to connect both programs over the network, may I suggest you take a look at Pyro4? Basically what that does for you is enable you to do normal Python method calls, but over the network, to code running on another computer or in another Python process. You (almost) don't have to worry about low-level network details with it.

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.