Calling Bird2 from Python script fails
Stavros Konstantaras
stavros.konstantaras at ams-ix.net
Mon Nov 28 16:08:59 CET 2022
Hi Toke,
Yes I do, I didn't share the whole code snippet but my_file.close() was immediately below that line. __
And after closing the output file I proceed on calling subprocess with the "birdc configure" command.
Best Regards
Stavros
On 28/11/2022, 12:54, "Toke Høiland-Jørgensen" <toke at toke.dk> wrote:
Stavros Konstantaras via Bird-users <bird-users at trubka.network.cz>
writes:
> Hi Gerdriaan,
>
> Thank you for your interest and asking those questions. Finally I found the issue and luckily was not a Bird2's fault but some weird python3 behavior. For the record:
> - The following does not work:
> my_file.write(template.render(nawas_routes).encode('ascii', 'ignore').decode('ascii'))
>
> - The following works:
> new_data = template.render(nawas_routes).encode('ascii', 'ignore').decode('ascii')
> my_file.write(new_data)
>
>
> Although the first expression is (syntactically and logically)
> correct, by the time the "birdc configure" was called/executed the
> config file was empty. Even if I put a 1-2-3 second time sleep the
> file was still empty and thus, Bird2 had nothing to read. Once, the
> Python3 script completes successfully and exits to the CLI, you could
> see however the new data in the "my_file. Thus, it was quite confusing
> to understand and find the issue.
Are you calling my_file.close() anywhere? Otherwise, the data will stay
in a buffer until the file *does* get closed, which will happen when the
Python script exits...
-Toke
More information about the Bird-users
mailing list