Skip to content
This repository has been archived by the owner on May 15, 2020. It is now read-only.

Commit

Permalink
Fixes 'RuntimeError: thread already started'
Browse files Browse the repository at this point in the history
  • Loading branch information
othrayte committed Sep 10, 2011
1 parent 88ab2b4 commit f35bb3e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions nbhttpconnection.py
Expand Up @@ -4,6 +4,7 @@
import os, sys
import time, socket
import urllib
import thread
import threading

try:
Expand All @@ -28,14 +29,12 @@
__status__ = "Production"

# Allows non-blocking http requests
class NBHTTPConnection(threading.Thread):
class NBHTTPConnection():
def __init__(self, host, port = None, strict = None, timeout = None):
self.rawConnection = httplib.HTTPConnection(host, port, strict, timeout)
self.responce = None
self.responceLock = threading.Lock()
self.closing = False

threading.Thread.__init__(self)

def request(self, method, url, body = None, headers = {}):
self.rawConnection.request(method, url, body, headers);
Expand All @@ -54,9 +53,9 @@ def getResult(self):

def go(self):
self.responceLock.acquire()
self.start()
thread.start_new_thread ( NBHTTPConnection._run, ( self, ) )

def run(self):
def _run(self):
self.responce = self.rawConnection.getresponse()
self.responceLock.release()

Expand Down

0 comments on commit f35bb3e

Please sign in to comment.