/usr/share/doc/python-urwid/examples/subproc.py is in python-urwid-doc 2.0.1-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #!/usr/bin/env python
import subprocess
import urwid
import os
import sys
factor_me = 362923067964327863989661926737477737673859044111968554257667
run_me = os.path.join(os.path.dirname(sys.argv[0]), 'subproc2.py')
output_widget = urwid.Text("Factors of %d:\n" % factor_me)
edit_widget = urwid.Edit("Type anything or press enter to exit:")
frame_widget = urwid.Frame(
header=edit_widget,
body=urwid.Filler(output_widget, valign='bottom'),
focus_part='header')
def exit_on_enter(key):
if key == 'enter': raise urwid.ExitMainLoop()
loop = urwid.MainLoop(frame_widget, unhandled_input=exit_on_enter)
def received_output(data):
output_widget.set_text(output_widget.text + data.decode('utf8'))
write_fd = loop.watch_pipe(received_output)
proc = subprocess.Popen(
['python', '-u', run_me, str(factor_me)],
stdout=write_fd,
close_fds=True)
loop.run()
proc.kill()
|