docker-py icon indicating copy to clipboard operation
docker-py copied to clipboard

Socket remaining open while getting logs from Generator object

Open nisarg1499 opened this issue 4 years ago • 1 comments

As per this documentation, I was using client.services.create method for creating the service in existing swarm network. The service was created successfully.

After that I tried to fetch the the logs using logs method of Service object. The parameters which I used in logs method were (follow=True, stdout=True, stderr=True). I kept follow=True as I wanted to fetch the logs as the execution of commands is done. I fetched the logs from generator object using for loop.

my_srv = client.services.create(.......)
logs = my_srv.logs(follow=True, stdout=True, stderr=True)
for log in logs:
    print(log)

When the execution of service is completed, at that time the socket remains open of generator object. Due to that, the for loop execution does not get completed even if the logs are over.

Currently I have handled this using thread deamon process which will be killed as soon as the execution of service is completed. But is there any other workaround?

nisarg1499 avatar Jun 01 '21 07:06 nisarg1499

I have same issue

mfatemipour avatar Nov 03 '23 12:11 mfatemipour