psycogreen
Advanced tools
| six | ||
| pytest | ||
| gevent | ||
| eventlet | ||
| psycopg2 |
| #!/usr/bin/env python | ||
| """A server to test with blocking I/O.""" | ||
| # Copyright (C) 2010-2018 Daniele Varrazzo <daniele.varrazzo@gmail.com> | ||
| # All rights reserved. See COPYING file for details. | ||
| from __future__ import print_function | ||
| import time | ||
| from wsgiref.simple_server import make_server | ||
| def wait_app(environ, start_response): | ||
| """An application serving blocking pages.""" | ||
| status = '200 OK' | ||
| headers = [('Content-type', 'text/plain')] | ||
| start_response(status, headers) | ||
| try: | ||
| secs = int(environ['PATH_INFO'].replace('/', '')) | ||
| except Exception: | ||
| secs = 0 | ||
| time.sleep(secs) | ||
| return [str(secs).encode('ascii')] | ||
| httpd = make_server('', 8000, wait_app) | ||
| print("Serving on port 8000...") | ||
| httpd.serve_forever() |
+4
| [flake8] | ||
| ignore = W503,E203 | ||
| max-line-length = 85 | ||
| exclude = env,tools/.black,tools/.flake8 |
+1
-1
@@ -1,2 +0,2 @@ | ||
| Copyright (c) 2010-2012, Daniele Varrazzo <daniele.varrazzo@gmail.com> | ||
| Copyright (c) 2010-2018, Daniele Varrazzo <daniele.varrazzo@gmail.com> | ||
| All rights reserved. | ||
@@ -3,0 +3,0 @@ |
+2
-3
@@ -1,4 +0,3 @@ | ||
| include COPYING MANIFEST.in README.rst setup.py | ||
| include COPYING MANIFEST.in project.toml README.rst setup.py tox.ini | ||
| recursive-include psycogreen *.py | ||
| recursive-include tests *.py | ||
| recursive-include tools *.py | ||
| recursive-include tests *.py *.txt |
+3
-2
@@ -1,4 +0,4 @@ | ||
| Metadata-Version: 1.0 | ||
| Metadata-Version: 1.1 | ||
| Name: psycogreen | ||
| Version: 1.0 | ||
| Version: 1.0.1 | ||
| Summary: psycopg2 integration with coroutine libraries | ||
@@ -101,2 +101,3 @@ Home-page: https://bitbucket.org/dvarrazzo/psycogreen | ||
| Classifier: Programming Language :: Python :: 2 | ||
| Classifier: Programming Language :: Python :: 3 | ||
| Classifier: Topic :: Database |
@@ -1,4 +0,4 @@ | ||
| Metadata-Version: 1.0 | ||
| Metadata-Version: 1.1 | ||
| Name: psycogreen | ||
| Version: 1.0 | ||
| Version: 1.0.1 | ||
| Summary: psycopg2 integration with coroutine libraries | ||
@@ -101,2 +101,3 @@ Home-page: https://bitbucket.org/dvarrazzo/psycogreen | ||
| Classifier: Programming Language :: Python :: 2 | ||
| Classifier: Programming Language :: Python :: 3 | ||
| Classifier: Topic :: Database |
@@ -5,2 +5,3 @@ COPYING | ||
| setup.py | ||
| tox.ini | ||
| psycogreen/__init__.py | ||
@@ -13,4 +14,5 @@ psycogreen/eventlet.py | ||
| psycogreen.egg-info/top_level.txt | ||
| tests/requirements.txt | ||
| tests/test_eventlet.py | ||
| tests/test_gevent.py | ||
| tools/wait_server.py | ||
| tests/wait_server.py |
| """Integration of psycopg2 with coroutine framework | ||
| """ | ||
| # Copyright (C) 2010-2012 Daniele Varrazzo <daniele.varrazzo@gmail.com> | ||
| # Copyright (C) 2010-2018 Daniele Varrazzo <daniele.varrazzo@gmail.com> | ||
| # All rights reserved. See COPYING file for details. | ||
| __version__ = '1.0' | ||
| __version__ = '1.0.1' |
@@ -6,3 +6,3 @@ """A wait callback to allow psycopg2 cooperation with eventlet. | ||
| # Copyright (C) 2010-2012 Daniele Varrazzo <daniele.varrazzo@gmail.com> | ||
| # Copyright (C) 2010-2018 Daniele Varrazzo <daniele.varrazzo@gmail.com> | ||
| # All rights reserved. See COPYING file for details. | ||
@@ -18,2 +18,3 @@ | ||
| def patch_psycopg(): | ||
@@ -24,6 +25,8 @@ """Configure Psycopg to be used with eventlet in non-blocking way.""" | ||
| "support for coroutines not available in this Psycopg version (%s)" | ||
| % psycopg2.__version__) | ||
| % psycopg2.__version__ | ||
| ) | ||
| extensions.set_wait_callback(eventlet_wait_callback) | ||
| def eventlet_wait_callback(conn, timeout=-1): | ||
@@ -40,3 +43,2 @@ """A wait callback useful to allow eventlet to work with Psycopg.""" | ||
| else: | ||
| raise psycopg2.OperationalError( | ||
| "Bad result from poll: %r" % state) | ||
| raise psycopg2.OperationalError("Bad result from poll: %r" % state) |
@@ -6,3 +6,3 @@ """A wait callback to allow psycopg2 cooperation with gevent. | ||
| # Copyright (C) 2010-2012 Daniele Varrazzo <daniele.varrazzo@gmail.com> | ||
| # Copyright (C) 2010-2018 Daniele Varrazzo <daniele.varrazzo@gmail.com> | ||
| # All rights reserved. See COPYING file for details. | ||
@@ -18,2 +18,3 @@ | ||
| def patch_psycopg(): | ||
@@ -24,6 +25,8 @@ """Configure Psycopg to be used with gevent in non-blocking way.""" | ||
| "support for coroutines not available in this Psycopg version (%s)" | ||
| % psycopg2.__version__) | ||
| % psycopg2.__version__ | ||
| ) | ||
| extensions.set_wait_callback(gevent_wait_callback) | ||
| def gevent_wait_callback(conn, timeout=None): | ||
@@ -40,3 +43,2 @@ """A wait callback useful to allow gevent to work with Psycopg.""" | ||
| else: | ||
| raise psycopg2.OperationalError( | ||
| "Bad result from poll: %r" % state) | ||
| raise psycopg2.OperationalError("Bad result from poll: %r" % state) |
+0
-1
| [egg_info] | ||
| tag_build = | ||
| tag_date = 0 | ||
| tag_svn_revision = 0 | ||
+14
-12
@@ -6,3 +6,3 @@ #!/usr/bin/env python | ||
| # Copyright (C) 2010-2012 Daniele Varrazzo <daniele.varrazzo@gmail.com> | ||
| # Copyright (C) 2010-2018 Daniele Varrazzo <daniele.varrazzo@gmail.com> | ||
@@ -19,2 +19,3 @@ | ||
| Programming Language :: Python :: 2 | ||
| Programming Language :: Python :: 3 | ||
| Topic :: Database | ||
@@ -26,15 +27,16 @@ """ | ||
| kwargs['long_description'] = open('README.rst').read() | ||
| except: | ||
| except Exception: | ||
| pass | ||
| setup( | ||
| name = 'psycogreen', | ||
| description = 'psycopg2 integration with coroutine libraries', | ||
| author = 'Daniele Varrazzo', | ||
| author_email = 'daniele.varrazzo@gmail.com', | ||
| url = 'https://bitbucket.org/dvarrazzo/psycogreen', | ||
| license = 'BSD', | ||
| packages = ['psycogreen'], | ||
| classifiers = [x for x in classifiers.split('\n') if x], | ||
| version = __version__, | ||
| **kwargs) | ||
| name='psycogreen', | ||
| description='psycopg2 integration with coroutine libraries', | ||
| author='Daniele Varrazzo', | ||
| author_email='daniele.varrazzo@gmail.com', | ||
| url='https://bitbucket.org/dvarrazzo/psycogreen', | ||
| license='BSD', | ||
| packages=['psycogreen'], | ||
| classifiers=[x for x in classifiers.split('\n') if x], | ||
| version=__version__, | ||
| **kwargs | ||
| ) |
| #!/usr/bin/env python | ||
| """A test to verify Psycopg collaboration with other blocking I/O. | ||
| Please run the script ``tools/wait_server.py`` in a separate shell to make the | ||
| Please run the script ``wait_server.py`` in a separate shell to make the | ||
| test work. | ||
@@ -10,3 +10,3 @@ | ||
| # Copyright (C) 2010-2012 Daniele Varrazzo <daniele.varrazzo@gmail.com> | ||
| # Copyright (C) 2010-2018 Daniele Varrazzo <daniele.varrazzo@gmail.com> | ||
| # All rights reserved. See COPYING file for details. | ||
@@ -16,12 +16,15 @@ | ||
| import eventlet | ||
| eventlet.monkey_patch() | ||
| eventlet.monkey_patch() # noqa | ||
| import psycogreen.eventlet | ||
| psycogreen.eventlet.patch_psycopg() | ||
| import urllib2 # green | ||
| psycogreen.eventlet.patch_psycopg() # noqa | ||
| from six.moves.urllib.request import urlopen # green | ||
| import psycopg2 | ||
| import logging | ||
| logging.basicConfig(level=logging.INFO, format="%(asctime)s %(message)s") | ||
@@ -33,2 +36,3 @@ logger = logging.getLogger() | ||
| def download(num, secs): | ||
@@ -38,5 +42,6 @@ url = "http://localhost:8000/%d/" % secs | ||
| logger.info("download %d start", i) | ||
| data = urllib2.urlopen(url).read() | ||
| urlopen(url).read() | ||
| logger.info("download %d end", i) | ||
| def fetch(num, secs): | ||
@@ -49,2 +54,3 @@ cur = conn.cursor() | ||
| logger.info("making jobs") | ||
@@ -58,2 +64,1 @@ pool = eventlet.GreenPool() | ||
| logger.info("join end") | ||
+13
-11
| #!/usr/bin/env python | ||
| """A test to verify Psycopg collaboration with other blocking I/O. | ||
| Please run the script ``tools/wait_server.py`` in a separate shell to make the | ||
| Please run the script ``wait_server.py`` in a separate shell to make the | ||
| test work. | ||
@@ -10,3 +10,3 @@ | ||
| # Copyright (C) 2010-2012 Daniele Varrazzo <daniele.varrazzo@gmail.com> | ||
| # Copyright (C) 2010-2018 Daniele Varrazzo <daniele.varrazzo@gmail.com> | ||
| # All rights reserved. See COPYING file for details. | ||
@@ -17,12 +17,15 @@ | ||
| import gevent.monkey | ||
| gevent.monkey.patch_all() | ||
| gevent.monkey.patch_all() # noqa | ||
| import psycogreen.gevent | ||
| psycogreen.gevent.patch_psycopg() | ||
| import urllib2 # green | ||
| psycogreen.gevent.patch_psycopg() # noqa | ||
| from six.moves.urllib.request import urlopen # green | ||
| import psycopg2 | ||
| import logging | ||
| logging.basicConfig(level=logging.INFO, format="%(asctime)s %(message)s") | ||
@@ -34,2 +37,3 @@ logger = logging.getLogger() | ||
| def download(num, secs): | ||
@@ -39,5 +43,6 @@ url = "http://localhost:8000/%d/" % secs | ||
| logger.info("download %d start", i) | ||
| data = urllib2.urlopen(url).read() | ||
| urlopen(url).read() | ||
| logger.info("download %d end", i) | ||
| def fetch(num, secs): | ||
@@ -50,7 +55,5 @@ cur = conn.cursor() | ||
| logger.info("making jobs") | ||
| jobs = [ | ||
| gevent.spawn(download, 2, 3), | ||
| gevent.spawn(fetch, 3, 2), | ||
| ] | ||
| jobs = [gevent.spawn(download, 2, 3), gevent.spawn(fetch, 3, 2)] | ||
@@ -60,2 +63,1 @@ logger.info("join begin") | ||
| logger.info("join end") | ||
| #!/usr/bin/env python | ||
| """A server to test with blocking I/O.""" | ||
| # Copyright (C) 2010-2012 Daniele Varrazzo <daniele.varrazzo@gmail.com> | ||
| # All rights reserved. See COPYING file for details. | ||
| import time | ||
| from wsgiref.simple_server import make_server | ||
| def wait_app(environ, start_response): | ||
| """An application serving blocking pages.""" | ||
| status = '200 OK' | ||
| headers = [('Content-type', 'text/plain')] | ||
| start_response(status, headers) | ||
| try: | ||
| secs = int(environ['PATH_INFO'].replace('/', '')) | ||
| except: | ||
| secs = 0 | ||
| time.sleep(secs) | ||
| return [ str(secs) ] | ||
| httpd = make_server('', 8000, wait_app) | ||
| print "Serving on port 8000..." | ||
| httpd.serve_forever() | ||
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
22301
1.65%18
12.5%