resurfaceio / logger-python

Log API calls with Python
Apache License 2.0
22 stars 6 forks source link

#26 POST requests on new threads with bounded queue #32

Closed monrax closed 2 years ago

monrax commented 3 years ago

Moved the try-except block from submit to a new post_request function nested inside submit, so that it works as a target when creating a new Thread. This thread doesn't block the calling thread (so that a new submission can be made from the main thread), instead a max_queue_depth attribute that defaults to 128 sets the upperbound limit of a Queue object, which can block if necessary until a free slot is available. When submit is called, given that the logger's queue attribute is not None, the corresponding msg is put in the queue and a new post_request thread is started. After each response, the first item in the queue is removed (NOTE: the first thread to have a response will perform the next dequeue operation, thus the item returned from the queue might not necessarily match the msg passed to that particular thread)

monrax commented 3 years ago

I assumed that the queue attribute of the BaseLogger object was intended for this purpose, but I'm not sure that this is the case. Please, let me know if something like this is what you had in mind @RobDickinson