How to stream POST data into Python requests?

后端 未结 2 1933
情话喂你
情话喂你 2021-01-13 06:19

I\'m using the Python requests library to send a POST request. The part of the program that produces the POST data can write into an arbitrary

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-13 07:10

    The only way of connecting a data producer that requires a push interface for its data sink with a data consumer that requires a pull interface for its data source is through an intermediate buffer. Such a system can be operated only by running the producer and the consumer in "parallel" - the producer fills the buffer and the consumer reads from it, each of them being suspended as necessary. Such a parallelism can be simulated with cooperative multitasking, where the producer yields the control to the consumer when the buffer is full, and the consumer returns the control to the producer when the buffer gets empty. By taking the generator approach you will be building a custom-tailored cooperative multitasking solution for your case, which will hardly end up being simpler compared to the easy pipe-based approach, where the responsibility of scheduling the producer and the consumer is entirely with the OS.

提交回复
热议问题