Skip to content

Commit 02d2609

Browse files
committed
Remove automatic monkey-patching for gevent based servers.
Bottle used to depend on monkey-patching to work with greenlet-based concurrency. This is no longer the case, so we can remove this error-prone and incomplete workaround from the bottle CLI startup logic. change: Bottle CLI no longer monkey-patches the python standard library when selecting the gevent or eventlet server adapters from the command line.
1 parent 10e3bc0 commit 02d2609

File tree

1 file changed

+25
-45
lines changed

1 file changed

+25
-45
lines changed

bottle.py

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,51 +19,6 @@
1919
__version__ = '0.14-dev'
2020
__license__ = 'MIT'
2121

22-
###############################################################################
23-
# Command-line interface ######################################################
24-
###############################################################################
25-
# INFO: Some server adapters need to monkey-patch std-lib modules before they
26-
# are imported. This is why some of the command-line handling is done here, but
27-
# the actual call to _main() is at the end of the file.
28-
29-
30-
def _cli_parse(args): # pragma: no coverage
31-
from argparse import ArgumentParser
32-
33-
parser = ArgumentParser(prog=args[0], usage="%(prog)s [options] package.module:app")
34-
opt = parser.add_argument
35-
opt("--version", action="store_true", help="show version number.")
36-
opt("-b", "--bind", metavar="ADDRESS", help="bind socket to ADDRESS.")
37-
opt("-s", "--server", default='wsgiref', help="use SERVER as backend.")
38-
opt("-p", "--plugin", action="append", help="install additional plugin/s.")
39-
opt("-c", "--conf", action="append", metavar="FILE",
40-
help="load config values from FILE.")
41-
opt("-C", "--param", action="append", metavar="NAME=VALUE",
42-
help="override config values.")
43-
opt("--debug", action="store_true", help="start server in debug mode.")
44-
opt("--reload", action="store_true", help="auto-reload on file changes.")
45-
opt('app', help='WSGI app entry point.', nargs='?')
46-
47-
cli_args = parser.parse_args(args[1:])
48-
49-
return cli_args, parser
50-
51-
52-
def _cli_patch(cli_args): # pragma: no coverage
53-
parsed_args, _ = _cli_parse(cli_args)
54-
opts = parsed_args
55-
if opts.server:
56-
if opts.server.startswith('gevent'):
57-
import gevent.monkey
58-
gevent.monkey.patch_all()
59-
elif opts.server.startswith('eventlet'):
60-
import eventlet
61-
eventlet.monkey_patch()
62-
63-
64-
if __name__ == '__main__':
65-
_cli_patch(sys.argv)
66-
6722
###############################################################################
6823
# Imports and Helpers used everywhere else #####################################
6924
###############################################################################
@@ -4526,6 +4481,31 @@ def wrapper(*args, **kwargs):
45264481
ext = _ImportRedirect('bottle.ext' if __name__ == '__main__' else
45274482
__name__ + ".ext", 'bottle_%s').module
45284483

4484+
###############################################################################
4485+
# Command-line interface ######################################################
4486+
###############################################################################
4487+
4488+
def _cli_parse(args): # pragma: no coverage
4489+
from argparse import ArgumentParser
4490+
4491+
parser = ArgumentParser(prog=args[0], usage="%(prog)s [options] package.module:app")
4492+
opt = parser.add_argument
4493+
opt("--version", action="store_true", help="show version number.")
4494+
opt("-b", "--bind", metavar="ADDRESS", help="bind socket to ADDRESS.")
4495+
opt("-s", "--server", default='wsgiref', help="use SERVER as backend.")
4496+
opt("-p", "--plugin", action="append", help="install additional plugin/s.")
4497+
opt("-c", "--conf", action="append", metavar="FILE",
4498+
help="load config values from FILE.")
4499+
opt("-C", "--param", action="append", metavar="NAME=VALUE",
4500+
help="override config values.")
4501+
opt("--debug", action="store_true", help="start server in debug mode.")
4502+
opt("--reload", action="store_true", help="auto-reload on file changes.")
4503+
opt('app', help='WSGI app entry point.', nargs='?')
4504+
4505+
cli_args = parser.parse_args(args[1:])
4506+
4507+
return cli_args, parser
4508+
45294509

45304510
def _main(argv): # pragma: no coverage
45314511
args, parser = _cli_parse(argv)

0 commit comments

Comments
 (0)