It would be preferable to change the Openwhisk python snippet Dockerfile to FROM python:3.5.2-alpine rather than FROM python:2.7.12-alpine
For a number of reasons including the trivial example issue below.
Whilst it may make a lot of sense to Apple, for example, to have OS X default to python 2.7 because OS X / MacOS has a big investment in python 2 system programs, it makes better sense really to have (new) OpenWhisk Python snippets written in python 3.
wsk action create pyAction pyProgram.py with statement (available since 2.6 - thus available to Openwhisk python snippets in python 2.7)with statement and need not be managed by the programmersmtplib) that have not been upgraded to python 3 and thus have no attribute __exit__If it were python 3 this would work without error
from smtplib import SMTP
with SMTP("domain.org") as smtp:
smtp.noop()
In python 2.7 this is generated:
AttributeError: SMTP instance has no attribute '__exit__'
We can do this the way we support multiple node or swift version, namely, as python (default to latest), python:2.7 and python:3.5.
Would it be possible for wsk action to look at a version.txt file for python 3.5 or python 2.7 if present?
@rabbah Is the request to support python 3 via the action kind property?
This enhancement will be in in the context of kind for python versions
wsk action create --kind python:3 myaction mysnippet.py
or
wsk action create --kind python:2 myaction mysnippet.py2
I'd prefer to simply drop python 2.7 rather than support both.
I'd prefer to simply drop python 2.7 rather than support both.
Works for me, I was not sure why the runtime got implemented with 2 instead of 3
User can always choose any python version, and any packages they need via docker actions.
User can always choose any python version, and any packages they need via docker actions.
My feelings too. Python snippets should be Python 3 and so should Docker actions in the sense that the _blackbox_ uses openwhisk/dockerskeleton to do its thing for actions in any language.
Note that if you write a Docker action in Python today you have to install python3 into the Alpine Linux and pip3 your Python packages... which is an unecessary complexity and opportunity for error and may introduce conflicts with the whisk's own python 2 stuff .
OK... We are now tantalizingly close on this one. Recent PRs have done much to get the codebase to be compatible with both Python 2 and Python 3. Note: this repo is ~90% Scala and only 1.5% Python but it does use Python is a few key areas.
We created a single Docker image that contained both Python 2 and Python 3 but that proved to be too big for daily use. Therefore the sense is that we should transition to a world where OpenWhisk majors in (defaults to) Python 3 and minors in Python 2.
We would make dockerskeleton into a Python 3 container.
For those who use the wsk syntax:
wsk action create myaction mysnippet.py # use dockerskeleton-based container
wsk action create --kind python:3 myaction mysnippet.py # use dockerskeleton-based container
wsk action create --kind python:2 myaction mysnippet.py # use python:2.7.12-alpine-based container
For those who do _not_ use the CLI, OpenWhisk will just assume their code is Python 3 to be deployed on the Python 3-based dockerskeleton container. It is not considered Pythonic to change file suffixes to .py2 and .py3 and reading file shebang lines is probably not worth the effort.
TODOs (in rough order of execution):
Also to consider: https://github.com/openwhisk/openwhisk/pull/1940 (venv vs. virtualenv), https://github.com/openwhisk/openwhisk/pull/1867, and https://github.com/openwhisk/openwhisk/pull/1510
Are there any Python 3-only PyPI modules that we should consider adding to the new dockerskeleton to provide folks an incentive to switch? I would vote for aiohttp (like requests on asyncio).
@rabbah @mrutkows Thanks to the merging of recent PRs, flake8 now finds no Python 3 syntax errors in this repo. #1903 now adds a new core/python2Action with appropriate Dockerfile and build.gradle to allow us to continue to run Python 2 actions after the Python 3 upgrade.
Now that #2007 is merged, we have two choices:
core/python2Action --or--Thoughts?
Without understanding all the implications (I hadn't realised how much work would be involved for 1.5% of Openwhisk code!) of going for the "Big Bang", it would seem to me preferable to upgrade core/actionProxy and core/pythonAction to Python 3.
Need for a --kind python:n option? Do we have any idea what impact this would have - i.e. can we quantify the number of applications' Openwhisk Containers in use that would require a --kind python:n option? i.e. be adversely impacted by things going over to Python 3
BTW it seems quite common for people to
import asyncio
import aiohttp
import requests
So if these libraries were available by default it would give a good range of functionality to applications deployed to an Openwhisk Container
Will make that happen.
Asyncio is built into Python 3.
aiohttp is awesome!
requests is essential (Don't leave home without it)
Update on our status for moving to Python 3... We have decided to go big bang (direct from Python 2.7.12 to 3.6.0) which makes it harder but we are still making progress. The checklist (in rough order of execution) now looks like this:
Others Python (non-blocking) issues I am still monitoring include: #1940 and #1510
Update on the journey getting Open Whisk to major on Python 3 and minor on Python 2...
~#1867~ solved most of the problems and ~#2044~ demonstrated the solutions to the remaining ones.
The checklist (in rough order of execution) now looks like this:
Update on the journey getting Open Whisk to major on Python 3 and minor on Python 2...
The checklist (in rough order of execution) now looks like this:
Closed by #1903 and commit https://github.com/openwhisk/openwhisk/commit/3a738e63b5bf4e0b042b3f8e5e5c5c063959d4c5.
Most helpful comment
@rabbah @mrutkows Thanks to the merging of recent PRs,
flake8now finds no Python 3 syntax errors in this repo. #1903 now adds a newcore/python2Actionwith appropriate Dockerfile and build.gradle to allow us to continue to run Python 2 actions after the Python 3 upgrade.Now that #2007 is merged, we have two choices:
core/python2Action--or--Thoughts?
What is required to make that happen?