1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Why is the print job not executed until the urwid application has finished?

Discussion in 'Main Forum' started by AFoeee, Sep 12, 2018.

  1. AFoeee

    AFoeee Guest

    I have written an urwid application which should print something when a button is pressed.

    However, after pressing the button, a print job is added, but it is not executed till the application is finished.

    About the execution environment:

    • os: ubuntu 18.04 (did also occur on raspbian)
    • python: 3.6.5
    • printer: a network printer (using CUPS)

    Could this be caused by a peculiarity of Linux or CUPS?

    I've also posted this question on stackoverflow, but I'm not sure if programming is really the problem.

    #! /usr/bin/env python3
    # -*- coding: utf-8 -*-

    import subprocess
    import urwid # installed via pip

    class App(object):
    PALETTE = [ ("revealFocus", "black", "dark cyan", "standout") ]

    def __init__(self):
    print_btn = urwid.AttrMap(urwid.Button("Print", on_press=self.print_dialog),

    exit_btn = urwid.AttrMap(urwid.Button("Exit", on_press=self.exit),

    pile = urwid.Pile([

    self.widget = urwid.Filler(pile,

    self.loop = urwid.MainLoop(self.widget,

    def print_dialog(self, btn):
    output = "Username: testuser\n".encode() \
    + "Password: p4ssw0rd\n".encode()

    # why is this not executed immediately?
    lpr = subprocess.Popen("/usr/bin/lpr", # on raspbian: /usr/bin/lp
    stdout=subprocess.DEVNULL, # proposed by stackoverflow user elias
    close_fds=True) # proposed by stackoverflow user elias

    def start(self):

    def exit(self, btn):
    raise urwid.ExitMainLoop()

    if __name__ == "__main__":
    app = App()

    Login To add answer/comment

Share This Page