EricssonResearch / calvin-base

Calvin is an application environment that lets things talk to things, among other things.
Apache License 2.0
282 stars 91 forks source link

web3 integration #96

Closed AzielioTor closed 6 years ago

AzielioTor commented 6 years ago

Hello Everyone! My team and I are working on getting Calvin to interact with smartcontracts, but this requires the use of web3.py which can only be used on python3.x. As calvin is developed on python 2.x, what is the best way for us to try and integrate?

It feels like a daunting task to rewrite all of the web3 framework to work on python2. My other thought is calling python3 scripts and getting results with the use of:

from subprocess import call
result = call(“python3 python3code.py”)

Is this the best way to go about it or has someone else run into the python versioning issue before and found a more elegant way to resolve this?

Thanks everyone! Aziel

olaan commented 6 years ago

Hey,

this is one way of doing it. Keep in mind that subprocess.call will block until the script has finished, so if you execute this from the main thread in the runtime, then the entire runtime will wait for it to finish. Note that this will only return the exit code from the python3 application. It is common to be interested in more than this, e.g. standard out and such, so you may want to use subprocess.Popen() instead.

Another way of doing it would be to have the python3 application running as a service and communicate with it using e.g. sockets or REST. For long-running jobs with communication going in both directions, sockets would probably be the preferred way.

On a side note, we are planning on moving over to python3, but there is as yet no set timeframe for it. I cannot promise it will be this year.

Cheers,

// Ola

olaan commented 6 years ago

I'm closing this issue now. If you have further questions, feel free to open a new one.

Cheers.