What Compatibility Issues Exist During the Migration?
- args difference
V1:
args = parser.parse_args()
After migration to V2, it will be:
args = parser.parse_args(args=[])
The sys.argv of Python runtime varies between the two versions.
For V2, it is ['/home/snuser/runtime/python3.6/server.py', '127.0.0.1:31536', '/opt/function/code'], whose last two parameters are not available for V1.
- asyncio difference
V1:
loop = asyncio.get_event_loop() loop.run_until_complete(func(arg1, arg2)) loop.close()
After migration to V2, it will be:
loop_tmp = asyncio.new_event_loop() asyncio.set_event_loop(loop_tmp) loop = asyncio.get_event_loop() loop.run_until_complete(func(arg1, arg2)) loop.close()
In V1, asyncio.get_event_loop() obtains the current event loop from the OS thread (main thread). It will throw RuntimeError in V2, because Python runtime of V2 does not run functions in the main thread.
To use asyncio in V2, create an event loop.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot