Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Somebody's terminal is dropping bits. I found a pile of them over in the corner.


devel / comp.lang.python / Re: First two bytes of 'stdout' are lost

SubjectAuthor
o Re: First two bytes of 'stdout' are lostOlivier B.

1
Re: First two bytes of 'stdout' are lost

<mailman.97.1712840985.3468.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=29846&group=comp.lang.python#29846

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: perso.olivier.barthelemy@gmail.com (Olivier B.)
Newsgroups: comp.lang.python
Subject: Re: First two bytes of 'stdout' are lost
Date: Thu, 11 Apr 2024 15:09:32 +0200
Lines: 43
Message-ID: <mailman.97.1712840985.3468.python-list@python.org>
References: <CA+cSArh=U-H6nW7nYBBD5v=ZUAvGpE1M_nB9BUoYzvca9XsKfA@mail.gmail.com>
<CA+cSArjxv==FPo9rpwGomMxU0k56d_cqocKHiAq1qDSFeYVqQw@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de /ArmMWoWxx4f6SnM77XzUgqfGiR592t5wACyIW9O3huA==
Cancel-Lock: sha1:u9kwDsGNP3JKc5PyRDBVHg5GYYw= sha256:iRZbgcGc6QlL8jI2mtBXHfxyoeY5M5GG9pWN64Ju6sc=
Return-Path: <perso.olivier.barthelemy@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=nUhUcrhq;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.005
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'looks': 0.02; 'this:':
0.03; 'issue.': 0.05; 'hopefully': 0.07; 'string': 0.07;
'subject:two': 0.09; 'import': 0.15; '2024': 0.16; 'api.': 0.16;
'c++': 0.16; 'changed:': 0.16; 'characters.': 0.16;
'manipulating': 0.16; 'print(': 0.16; 'solves': 0.16; 'stdout':
0.16; 'stdout.': 0.16; 'variable,': 0.16; 'python': 0.16; 'api':
0.17; 'instead': 0.17; 'to:addr:python-list': 0.20; 'written':
0.22; 'code': 0.23; 'run': 0.23; 'idea': 0.24; 'to:name:python-
list@python.org': 0.24; 'seems': 0.26; 'answering': 0.26; 'ideas':
0.28; 'wrong': 0.28; 'extract': 0.32; 'point,': 0.32; 'message-
id:@mail.gmail.com': 0.32; 'but': 0.32; 'someone': 0.34; 'header
:In-Reply-To:1': 0.34; 'received:google.com': 0.34; 'running':
0.34; 'trying': 0.35; 'from:addr:gmail.com': 0.35; 'using': 0.37;
'two': 0.39; 'quite': 0.39; 'this,': 0.39; 'use': 0.39;
'something': 0.40; 'point.': 0.62; 'limited': 0.62; 'now,': 0.67;
'worked': 0.67; 'right': 0.68; 'exactly': 0.68; 'compared': 0.71;
'content': 0.72; 'capture': 0.84; 'characters': 0.84; 'clue':
0.84; 'jeu.': 0.84; 'ruled': 0.84; 'subject:First': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1712840983; x=1713445783; darn=python.org;
h=content-transfer-encoding:to:subject:message-id:date:from
:in-reply-to:references:mime-version:from:to:cc:subject:date
:message-id:reply-to;
bh=z49jZuv8aZdpcqHUsyV3CQgKeKR6SGCbhm7EtvmZu68=;
b=nUhUcrhqTYT5U5KdeUmIIs7P8AFtgJnu8urS2WVmpdYtmeSTMNw/D/OXLgZqnKVKYg
oLMvRLNNhHcXQis2L3DSu9vFpSd6gtXNcJxvSynXFhtsobyz9pYY8dXEGUhntnAg5y41
5grSRZ4WBf3h3vrhDTxCJ0k15atM3z9DfA1KRnkZPPRNhPQMHIfdp4Or1xuHEtMg2EJa
M6PdwCeHAaSWqu4ix08VpzPeb6QCLJQzXnQRiF83PNirij0tkF/FbbJkURCT/MxxGrT6
BBf2TtEMtMhJRNJ5I0xCllbn4oKiHFc7xSRlKAp6uMbf1YRHPTtSj75HP5KZeR00Dqk6
QlWg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1712840983; x=1713445783;
h=content-transfer-encoding:to:subject:message-id:date:from
:in-reply-to:references:mime-version:x-gm-message-state:from:to:cc
:subject:date:message-id:reply-to;
bh=z49jZuv8aZdpcqHUsyV3CQgKeKR6SGCbhm7EtvmZu68=;
b=DgmIsNRAR46XysQqtpJgM4Q1f0EcABwgNLCyDaPcLh1y6iRxYWBtM6OJtLAGr77Wnt
xwTvFR+XbYzvs6IyM2E/AhHaro8lOSUfugXYuz7X82spVFluYUO9FhGPi9/KQtkxFhQH
P21K+8eTSzas6r48knjtzvFI+YgBNYw+gHIIlarp/YcwW0DBmbV/WasYyf7lOK3G0eFz
I+7+P/yC5WLLCPQZ6jmSl8knifcAYzJnLr6zZ2lRo4ipuPCHYymRChOOr7CSTfpX1Iml
tZmRIYlOqPS3+lyTmOipoXIiJ1tMtbVmhXEsNnWhB96GEQsqkJ4ajJSrdlZeJgdk0+Pt
3wUQ==
X-Gm-Message-State: AOJu0YxGoNRk83n5CEhl1v7298r4Jf1mHjviyyrbZaJqc3U7/dUyfFDq
jf6IK6Q1O9TjR1Rr4hybVjVp8FHZPAyFzjrh2f+DrjHwoaa9PnTKbj/m9iCgUO25kUDOaouGykx
wOb6V0vm3w4VOwkIojjkTOT28o/RuSRwW
X-Google-Smtp-Source: AGHT+IHgt53vpu+HAEjVoOSj7Mmqwb9w72mCTNbOH24mBCBztnrTYtA+Zfh7uiY9LkXO5rD6OJPPSjwcCXVapVYo8hs=
X-Received: by 2002:a17:906:190a:b0:a51:ce66:cf12 with SMTP id
a10-20020a170906190a00b00a51ce66cf12mr2753126eje.35.1712840983296; Thu, 11
Apr 2024 06:09:43 -0700 (PDT)
In-Reply-To: <CA+cSArh=U-H6nW7nYBBD5v=ZUAvGpE1M_nB9BUoYzvca9XsKfA@mail.gmail.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CA+cSArjxv==FPo9rpwGomMxU0k56d_cqocKHiAq1qDSFeYVqQw@mail.gmail.com>
X-Mailman-Original-References: <CA+cSArh=U-H6nW7nYBBD5v=ZUAvGpE1M_nB9BUoYzvca9XsKfA@mail.gmail.com>
 by: Olivier B. - Thu, 11 Apr 2024 13:09 UTC

Partly answering myself:

For some reason, right after mystdout has been created, i now have to
do mystdout.seek(0) and this solves the issue.

No idea why though..

Le jeu. 11 avr. 2024 à 14:42, Olivier B.
<perso.olivier.barthelemy@gmail.com> a écrit :
>
> I am trying to use StringIO to capture stdout, in code that looks like this:
>
> import sys
> from io import StringIO
> old_stdout = sys.stdout
> sys.stdout = mystdout = StringIO()
> print( "patate")
> mystdout.seek(0)
> sys.stdout = old_stdout
> print(mystdout.read())
>
> Well, it is not exactly like this, since this works properly
>
> This code is actually run from C++ using the C Python API.
> This worked quite well, so the code was right at some point. But now,
> two things changed:
> - Now using python 3.11.7 instead of 3.7.12
> - Now using only the python limited C API
>
> And it seems that now, mystdout.read() always misses the first two
> characters that have been written to stdout.
>
> My first ideas was something related to the BOM improperly truncated
> at some point, but i am manipulating UTF-8, so the bom would be 3
> bytes, not 2.
>
> I ruled out wrong C++ code to extract the string from the python
> variable, since running a python print of the content of mystdout in
> the real stdout also misses the two first characters.
>
> Hopefully someone has a clue on what would have changed in Python for
> this to stop working compared to python 3.7?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor