Skip to content

Instantly share code, notes, and snippets.

from sqlalchemy import event
from sqlalchemy.engine import Engine
import time
import logging
logging.basicConfig()
logger = logging.getLogger("myapp.sqltime")
logger.setLevel(logging.DEBUG)
@event.listens_for(Engine, "before_cursor_execute")
pip install virtualenv
Collecting virtualenv
/usr/local/lib/python2.7/site-packages/pip-8.1.0-py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
SNIMissingWarning
/usr/local/lib/python2.7/site-packages/pip-8.1.0-py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Using cached virtualenv-15.1.0-py2.py3-none-any.whl
Installing collected pac
>>> import numpy as np
>>> weather_yesterday = pd.DataFrame(np.random.randn(10, 5))
>>>
>>> weather_yesterday
0 1 2 3 4
0 -1.022778 -1.146957 -0.455922 3.330690 1.457040
1 -1.694324 0.830800 -0.440014 2.544319 -1.742110
2 -0.434218 0.432943 -1.952516 0.695923 0.830594
3 0.139740 0.170379 0.417473 -0.552355 -1.183856
4 -0.257754 1.197875 0.312274 0.806411 1.171922
"""
Helper module for spawning multiple asynchronous http requests using co-routines & futures,
powered by `asyncio` & `aiohttp` libraries, compatible only with `python 3.5 and above`
referring -
a task: as a individual unit of work, that awaits on response from a http request
a job: as a combined unit of all the tasks, that gathers all responses together
"""
2017-04-06 09:29:43,292 - __main__ - INFO - started task: 1
2017-04-06 09:29:43,303 - __main__ - INFO - started task: 2
2017-04-06 09:29:43,313 - __main__ - INFO - started task: 3
2017-04-06 09:29:43,323 - __main__ - INFO - started task: 4
2017-04-06 09:29:43,333 - __main__ - INFO - started task: 5
2017-04-06 09:29:48,365 - __main__ - INFO - finished task: 5 , process took: 5.032242774963379
2017-04-06 09:29:48,367 - __main__ - INFO - finished task: 2 , process took: 5.064499855041504
2017-04-06 09:29:48,368 - __main__ - INFO - finished task: 1 , process took: 5.076158046722412
2017-04-06 09:29:48,536 - __main__ - INFO - finished task: 4 , process took: 5.213091850280762
Traceback (most recent call last):
File "telescope/backend/telescope_api/async_helpers/http_requests_bug_file.py", line 178, in <module>
job1.run_job()
File "telescope/backend/telescope_api/async_helpers/http_requests_bug_file.py", line 133, in run_job
io_event_loop.run_until_complete(future=self.process_job_response())
File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/base_events.py", line 387, in run_until_complete
return future.result()
File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/futures.py", line 274, in result
raise self._exception
File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/tasks.py", line 239, in _step
FROM python:3.7.2-alpine3.9 as base-env
RUN pip3 install pipenv
COPY Pipfile Pipfile
COPY Pipfile.lock Pipfile.lock
RUN pipenv install --system