Skip to content

Commit

Permalink
Merge branch 'eventlet' into 0.10-maintenance
Browse files Browse the repository at this point in the history
Backporting this
  • Loading branch information
untitaker committed Feb 1, 2015
2 parents e7e5a7f + 8bc8b1a commit d115941
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Version 0.10.1
(bugfix release, release date to be decided)

- Fixed regression with multiple query values for URLs (pull request ``#667``).
- Fix issues with eventlet's monkeypatching and the builtin server (pull
request ``#663``).

Version 0.10
------------
Expand Down
26 changes: 26 additions & 0 deletions tests/test_serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""
import os
import ssl
import subprocess
import textwrap


Expand Down Expand Up @@ -171,3 +172,28 @@ def real_app(environ, start_response):
r = requests.get(server.url)
assert r.status_code == 200
assert r.content == b'hello'


def test_monkeypached_sleep(tmpdir):
# removing the staticmethod wrapper in the definition of
# ReloaderLoop._sleep works most of the time, since `sleep` is a c
# function, and unlike python functions which are descriptors, doesn't
# become a method when attached to a class. however, if the user has called
# `eventlet.monkey_patch` before importing `_reloader`, `time.sleep` is a
# python function, and subsequently calling `ReloaderLoop._sleep` fails
# with a TypeError. This test checks that _sleep is attached correctly.
script = tmpdir.mkdir('app').join('test.py')
script.write(textwrap.dedent('''
import time
def sleep(secs):
pass
# simulate eventlet.monkey_patch by replacing the builtin sleep
# with a regular function before _reloader is imported
time.sleep = sleep
from werkzeug._reloader import ReloaderLoop
ReloaderLoop()._sleep(0)
'''))
subprocess.check_call(['python', str(script)])
6 changes: 5 additions & 1 deletion werkzeug/_reloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,13 @@ def _walk(node, path):


class ReloaderLoop(object):
_sleep = staticmethod(time.sleep) # monkeypatched by testsuite
name = None

# monkeypatched by testsuite. wrapping with `staticmethod` is required in
# case time.sleep has been replaced by a non-c function (e.g. by
# `eventlet.monkey_patch`) before we get here
_sleep = staticmethod(time.sleep)

def __init__(self, extra_files=None, interval=1):
self.extra_files = set(os.path.abspath(x)
for x in extra_files or ())
Expand Down

0 comments on commit d115941

Please sign in to comment.