IBT-FMI / COSplay

Contrast Optimized Stimulation player
http://cosplay.readthedocs.io/en/latest
GNU General Public License v3.0
2 stars 3 forks source link

Support of different python version #5

Closed faymanns closed 7 years ago

faymanns commented 7 years ago

The scanner computer in the lab only has python 2.4.3 installed. I did a bit of digging on the issue of making a script work in python 2 and 3 and most sources suggest to only support python 2.6+ and 3.3+. @TheChymera, you said you have experience with this. How do you think we should go about?

TheChymera commented 7 years ago

Wow. Python 2.4.* is really really old. Generally I test on python 2.7 and python 3.4. In the future I will also test on 3.6.

As I mentioned before: most of the differences between python versions are new features. So when you use an older interpreter, you would be getting an exception. It is thus not that difficult to make your code compatible with all the versions. You just develop on a newer version, then test it on the old one, where you can catch the exceptions and reproduce the missing feature in a way which does not have to be compatible with python versions which don't trigger the exception.

What I suggest it:

faymanns commented 7 years ago

My distro comes with Python 2.7, but I have Python 3.5 installed and used that for now.

TheChymera commented 7 years ago

3.5 should be close enough to 3.6..

faymanns commented 7 years ago

Is this 91a58f254628bcfda65441a1cdb19995e919447d what you had in mind when you said catching the exceptions?

TheChymera commented 7 years ago

Yes, though I don't understand why you have to use eval() in the default statement.

faymanns commented 7 years ago

The interpreter parses the entire file before executing the script, and that way the SyntaxError is not caught. Using eval works around this because the code inside is only parsed during execution.

TheChymera commented 7 years ago

cool, I was actually wondering how we might address this case.

faymanns commented 7 years ago

The code works fine for python 2.7 and 3.6 now. For 2.4 there is no json module. We could work around this by using a third-party module called simplejson. However, simplejson droped support for python 2.4 in 2010 and we would have to use an old version. Further down the road one runs into similar issues for argparse and pyserial.

faymanns commented 7 years ago

I just installed python 3.6 on the 7T computer and it appearers to solve our connection problem. I'll test it some more, but if this turns out to be true, I suggest we only provide only limited support for python 2.7. We could simply tell users that python2.7 might not work with certain (old) kernels. Installing python3 seems like the smaller burden compared to messing with the kernel.

TheChymera commented 7 years ago

Wow, very good news (if this actually turns out to be true - it sounds like a very implausible fix). Don't forget that the 7T computer connection environment is currently not burdened by the acquisition connection. That may have a greater impact on whether or not kernel drivers/dispatchers fail than the python version does.

Ideally we would clean up all of our previous kernel-version-based fix attempts and then try to reproduce both the error with earlier python versions, and the absence of the error with py3.6 (in the current, broken, scanner state), finally we should reproduce both scenarios again after the preamplifier is fixed.