Skip to content

Instantly share code, notes, and snippets.

View aaronpolhamus's full-sized avatar
💭
🤘🤓🤘

Aaron Polhamus aaronpolhamus

💭
🤘🤓🤘
View GitHub Profile
@aaronpolhamus
aaronpolhamus / redis_handlers.py
Created August 9, 2020 02:06
task locking with redis + celery
"""Task locking with redis in celery is hard, and good examples are tough to come by. This is the approach that's
worked for me, based on great work that other folks have posted:
* https://breadcrumbscollector.tech/what-is-celery-beat-and-how-to-use-it-part-2-patterns-and-caveats/
* http://loose-bits.com/2010/10/distributed-task-locking-in-celery.html
* https://redis.io/topics/distlock
This isn't polished,but hopefully it's useful. To verify it in our local test env we register the following test task in
our definitions file:
*** definitions.py ***
# [1] Docker installation: https://docs.docker.com/install/linux/docker-ce/fedora/
# [2] Docker compose: https://github.com/Yelp/docker-compose/blob/master/docs/install.md
# [3] NVIDIA docker installation: https://github.com/NVIDIA/nvidia-docker/issues/553#issuecomment-381075335
# [4] Tensorflow docker installation: https://www.tensorflow.org/install/docker
# [1] install dnf-plugins-core
sudo dnf -y install dnf-plugins-core
# [1] setup stable repository
sudo dnf config-manager \
# Credits:
# [1] https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html (CUDA)
# [2] https://www.if-not-true-then-false.com/2015/fedora-nvidia-guide/ (Drivers)
yum install nano
# In /etc/sysconfig/selinux update to SELINUX=disabled (takes down firewall and speeds up downloads)
# [1] Install kernel headers
sudo dnf install kernel-devel-$(uname -r) kernel-headers-$(uname -r)
from datetime import datetime
from airflow.models import DAG
from airflow.operators.python_operator import PythonOperator
DAG = DAG(
dag_id='scheduler_test_dag',
start_date=datetime(2017, 9, 9, 4, 0, 0, 0), #..EC2 time. Equal to 11pm hora México
max_active_runs=1,
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@aaronpolhamus
aaronpolhamus / api_demo.py
Created June 16, 2017 00:55
Python API client demo for Google Drive SDK
#!/usr/bin/env python
from __future__ import print_function
import os
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
try:
import argparse
import numpy as np
import cv2
file_name = '/home/ubuntu/motocross.mp4'
cap = cv2.VideoCapture(file_name)
counter = 0
while(True):
# Capture frame-by-frame
@aaronpolhamus
aaronpolhamus / plot.py
Created June 8, 2016 20:55
run this script interactively to test whether python is connecting to X11 as expected
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.0, 2.0, 0.01)
s = np.sin(2*np.pi*t)
plt.plot(t, s)
plt.xlabel('time (s)')
plt.ylabel('voltage (mV)')