Help me with a bytes decoding problem in python 3

J dreadpiratejeff at gmail.com
Thu Jun 21 18:30:48 EDT 2012


On Thu, Jun 21, 2012 at 5:54 PM, Chris Angelico <rosuav at gmail.com> wrote:
> On Fri, Jun 22, 2012 at 7:47 AM, J <dreadpiratejeff at gmail.com> wrote:
>> \xe2\x86\xb3
>
> This is the UTF-8 encoded form of U+21B3, which is the DOWNWARDS ARROW
> WITH TIP RIGHTWARDS character that you're showing. That's what the
> "bytecode" you're seeing is. You may be able to ask the underlying
> program to make its output in a cleaner format - try looking for a
> --porcelain option or similar - but as I see it, everything in Python
> is doing what it ought to do.
>
> Or am I misunderstanding your question?
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list

No, that's exactly what was choking my python program...

And you hit the nail on the head.  Apparently, if I run xinput using
default output (what we were doing originally) you get those
characters.  If you run it like so:

xinput list --name-only

you get a clean, text only list of only the names of the various input
devices found.  So doing that, after an afternoon of pulling my hair
out over this mess, makes the program work as it's supposed to.

What confuses me though, is that the program calls that function
twice, and this works fine the first time around, but fails the
second.  The function is called before rebooting the machine, then is
called again after rebooting the machine and compares the output of
various system info commands to make sure no hardware disappeared
after a reboot.

This was not an issue in Python 2.x, it's only on the Python 3
conversion this occurred. :/ In fact, if I change the shebang from
python3 back to python2.7, it works beautifully.

In the log file, this appears the first time that the xinput command is run:
2012-06-21 18:02:43,043 INFO     Gathering hardware information...
2012-06-21 18:02:43,043 DEBUG    Executing: 'xinput list'...
2012-06-21 18:02:43,052 DEBUG    Output:
- returncode:
0
- stdout:
⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ Logitech Unifying Device. Wireless PID:1017       id=9    [slave
 pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad                id=12   [slave  pointer  (2)]
⎜   ↳ MCE IR Keyboard/Mouse (ite-cir)           id=14   [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Laptop_Integrated_Webcam_2M               id=8    [slave  keyboard (3)]
    ↳ HID 413c:8157                             id=10   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=11   [slave  keyboard (3)]
    ↳ Dell WMI hotkeys                          id=13   [slave  keyboard (3)]
    ↳ ITE8708 CIR transceiver                   id=15   [slave  keyboard (3)]

2012-06-21 18:02:43,053 DEBUG    Touchpad and Keyboard:
⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ Logitech Unifying Device. Wireless PID:1017       id=9    [slave
 pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad                id=12   [slave  pointer  (2)]
⎜   ↳ MCE IR Keyboard/Mouse (ite-cir)           id=14   [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Laptop_Integrated_Webcam_2M               id=8    [slave  keyboard (3)]
    ↳ HID 413c:8157                             id=10   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=11   [slave  keyboard (3)]
    ↳ Dell WMI hotkeys                          id=13   [slave  keyboard (3)]
    ↳ ITE8708 CIR transceiver                   id=15   [slave  keyboard (3)]

(it appears twice because I ran it in debug mode)

but after the reboot, it chokes:

2012-06-21 18:03:56,396 INFO     reboot operations remaining: 0
2012-06-21 18:03:56,396 INFO     Reboot time: 0:01:13.396280
2012-06-21 18:04:27,201 INFO     Gathering hardware information...
2012-06-21 18:04:27,201 DEBUG    Executing: 'xinput list'...
2012-06-21 18:07:22,985 DEBUG    Removing desktop file
('/home/bladernr/.config/autostart/pm_test.desktop')...
2012-06-21 18:07:22,986 DEBUG    Restoring sudoers configuration...
2012-06-21 18:07:22,986 DEBUG    Executing: "sed -i -e '/#
Automatically added by pm.py/,+1d' /etc/sudoers"...
2012-06-21 18:07:22,993 DEBUG    Restoring autologin configuration...
2012-06-21 18:07:23,013 INFO     Reboot test cancelled by user

Everything after "Executing: 'xinput list'..." is where I manually
cancelled the run because it stuck.

I'm wondering now... the way it works is that the program is run from
a user terminal/console.  however, on the other side (after the reboot
is done) it runs via an autostart script after the user is logged in,
and thus runs outside of the terminal.  So I wonder if THAT could be
the root cause of this headache...  maybe there's something about the
program being run outside of a user shell and generating those
characters that causes the hang.

At this point it's more an academic excercise, since I've got a viable
workaround...

in anycase, I was able to change the output of xinput and that fixed
the problem in a rather simple manner.



More information about the Python-list mailing list