Calling Bird2 from Python script fails
Toke Høiland-Jørgensen
toke at toke.dk
Mon Nov 28 12:53:02 CET 2022
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