Skip to content

Commit f56a825

Browse files
author
Jan Pobříslo
committed
Add --twisted to bpython.urwid and use it for --plugin and --server.
This uses the currently installed reactor (and installs the default implicitly if necessary), as opposed to explicitly installing a default reactor. This is useful for some bpython embedding usecases where a reactor is already installed by the time bpython.urwid.main() is called, and it fixes a bug where bpython defaults to the select reactor instead of twisted's default.
1 parent b97f477 commit f56a825

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

bpython/urwid.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,8 +1103,11 @@ def main(args=None, locals_=None, banner=None):
11031103
# TODO: maybe support displays other than raw_display?
11041104
config, options, exec_args = bpargs.parse(args, (
11051105
'Urwid options', None, [
1106+
Option('--twisted', '-T', action='store_true',
1107+
help=_('Run twisted reactor.')),
11061108
Option('--reactor', '-r',
1107-
help=_('Run a reactor (see --help-reactors).')),
1109+
help=_('Select specific reactor (see --help-reactors). '
1110+
'Implies --twisted.')),
11081111
Option('--help-reactors', action='store_true',
11091112
help=_('List available reactors for -r.')),
11101113
Option('--plugin', '-p',
@@ -1133,8 +1136,8 @@ def main(args=None, locals_=None, banner=None):
11331136
('bold ' + name, color + ',bold', background, monochrome)
11341137
for name, color, background, monochrome in palette])
11351138

1136-
if (options.server or options.plugin) and not options.reactor:
1137-
options.reactor = 'select'
1139+
if options.server or options.plugin:
1140+
options.twisted = True
11381141

11391142
if options.reactor:
11401143
try:
@@ -1153,6 +1156,14 @@ def main(args=None, locals_=None, banner=None):
11531156
options.reactor,))
11541157
return
11551158
event_loop = TwistedEventLoop(reactor)
1159+
elif options.twisted:
1160+
try:
1161+
from twisted.internet import reactor
1162+
except ImportError:
1163+
sys.stderr.write('No reactors are available. Please install '
1164+
'twisted for reactor support.\n')
1165+
return
1166+
event_loop = TwistedEventLoop(reactor)
11561167
else:
11571168
# None, not urwid.SelectEventLoop(), to work with
11581169
# screens that do not support external event loops.

0 commit comments

Comments
 (0)