I am working on a client for a web service using pycurl. The client opens a connection to a stream service and spawns it into a separate thread. Here's a stripped down version of how the connection is set up:
def _setup_connection(self):
self.conn = pycurl.Curl()
self.conn.setopt(pycurl.URL, FILTER_URL)
self.conn.setopt(pycurl.POST, 1)
.
.
.
self.conn.setopt(pycurl.HTTPHEADER, headers_list)
self.conn.setopt(pycurl.WRITEFUNCTION, self.local_callback)
def up(self):
if self.conn is None:
self._setup_connection()
self.perform()
Now, when i want to shut the connection down, if I call
self.conn.close()
I get the following exception:
error: cannot invoke close() - perform() is currently running
Which, in some way makes sense, the connection is constantly open. I've been hunting around and cant seem to find any way to circumvent this problem and close the connection cleanly.