Skip to content

Python

Develop Colab Notebooks with Visual Studio Code

For those who work frequently with Jupyter notebooks, Google Colab is a fantastic tool that allows developers to create, edit, and share their Python code through a web-based interface. However, sometimes we may prefer to use our own local development environment like Visual Studio Code (VS Code), especially if it means we get access to many of its helpful features. This guide will walk you through the process of developing your Google Colab notebooks with VS Code.

The key to this process is using a GitHub repository as a bridge to connect your local development environment (VS Code) with Google Colab.

Asyncio Is Not Parallelism

Also posted at medium.com.
You may have heard that Python asyncio is concurrent but not parallel programming. But how? I will explain it with simple examples.

Let’s start with a perfect concurrent example #1

import asyncio
import time

async def say_after(delay, what):
    print(time.time(),'Start say_after(%s, %s)' % (delay,what))
    await asyncio.sleep(delay)
    print(time.time(),what)

async def main():
    start_time = time.time()
    print(start_time, 'Before creating tasks.')
    task1 = asyncio.create_task(say_after(1, 'hello'))
    task2 = asyncio.create_task(say_after(2, 'world'))    
    await task1
    await task2     
    end_time = time.time()
    print('Total time elapsed: %.2f seconds' % (end_time - start_time))

asyncio.run(main())