Elegantly activating a virtualenv in a Dockerfile

When you’re packaging your Python application in a Docker image, you’ll often use a virtualenv. For example, you might be doing a multi-stage build in order to get smaller images. Since you’re using a virtualenv, you need to activate it—but if you’re just getting started with Dockerfiles, the naive way doesn’t work. And even if you do know how to do it, the usual method is repetitive and therefore error-prone. There is a simpler way of activating a virtualenv, which I’ll demonstrate in this article. But first, we’ll go over some of the other, less elegant (or broken!) ways you might do it. A note: outside the specific topic under discussion, the Dockerfiles in this article are not examples of best practices, since that would involve many extraneous details that would make the main point harder to understand.

Source : Elegantly activating a virtualenv in a Dockerfile

Python Multiprocessing Example – JournalDev

from multiprocessing import Queuecolors = [‘red’, ‘green’, ‘blue’, ‘black’]cnt = 1# instantiating a queue objectqueue = Queue()print(‘pushing items to queue:’)for color in colors: print(‘item no: ‘, cnt, ‘ ‘, color) queue.put(color) cnt += 1print(‘\npopping items from queue:’)cnt = 0while not queue.empty(): print(‘item no: ‘, cnt, ‘ ‘, queue.get()) cnt += 1

Source : Python Multiprocessing Example – JournalDev