Ticket #51 (closed defect: fixed)

Opened 5 years ago

Last modified 5 years ago

Won't emit a document until the next document is available

Reported by: edward@… Owned by: xi
Priority: normal Component: pyyaml
Severity: normal Keywords:
Cc:

Description

parse_document_end won't emit an event until it has seen the next token after the document end. This makes it difficult to use PyYAML to parse live streams of documents in a timely way, because the next document may not actually be available for some undetermined amount of time.

Using PyYAML-3.04.

Attachments

test_socket.py Download (1.0 KB) - added by edward@… 5 years ago.
Program demonstrates problem

Change History

Changed 5 years ago by xi

Does the stream contain the document end marks: "...\n"? These marks are necessary for parsing live streams.

Changed 5 years ago by edward@…

Program demonstrates problem

Changed 5 years ago by edward@…

Yes, the stream contains "...\n".

I just attached a script that demonstrates the issue. Run it once with "--server" and once without to test over loopback.

You'll see that the receiving side is always one message behind the sending side.

I think the problem is on parser.py line 189. This loop won't exit until the next non-DocumentEndToken? is seen. If no token is available, it blocks. This only seems necessary if multiple DocumentEndTokens? will occur in the stream -- is that even legal?

You'll see in the script that I'm wrapping a socket object to get a stream with "read" and "write". I have also tried the built-in "socket.makefile", but this performs even worse, because the read doesn't return any data until the whole buffer is full (or EOF).

Changed 5 years ago by xi

  • status changed from new to closed
  • resolution set to fixed

Fixed in [249] and [250].

Thanks for the bug report. Your analysis of the problem is correct. Multiple document end indicators are, indeed, allowed by the yaml specification, ironically, to make emitting a stream of yaml documents easier.

Changed 5 years ago by edward@…

Thanks for the quick resolution.

Add/Change #51 (Won't emit a document until the next document is available)

Author


E-mail address and user name can be saved in the Preferences.


Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.