本文整理汇总了Python中thread.start_new函数的典型用法代码示例。如果您正苦于以下问题:Python start_new函数的具体用法?Python start_new怎么用?Python start_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了start_new函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_pipe
def init_pipe():
try:
thread.start_new(socket_output_thread, ())
thread.start_new(socket_input_thread,())
except:
print "Could nor start pipe thread ...."
exit()
示例2: dispecher
def dispecher(self):
"""receiving clients and their distribution in the processing flow"""
while True:
connection, address = self._sockobj.accept()
print('server connected by', address)
print('at', self.now())
thread.start_new(self.handleClient, (connection, address,))
示例3: run
def run(self, nworkers):
if not self.work:
return # Nothing to do
for i in range(nworkers-1):
thread.start_new(self._worker, ())
self._worker()
self.todo.acquire()
示例4: test_wait
def test_wait(self):
for i in range(NUM_THREADS):
thread.start_new(self.f, (i,))
time.sleep(LONGSLEEP)
a = self.alive.keys()
a.sort()
self.assertEquals(a, range(NUM_THREADS))
prefork_lives = self.alive.copy()
if sys.platform in ['unixware7']:
cpid = os.fork1()
else:
cpid = os.fork()
if cpid == 0:
# Child
time.sleep(LONGSLEEP)
n = 0
for key in self.alive:
if self.alive[key] != prefork_lives[key]:
n += 1
os._exit(n)
else:
# Parent
self.wait_impl(cpid)
# Tell threads to die
self.stop = 1
time.sleep(2*SHORTSLEEP) # Wait for threads to die
示例5: start
def start(self):
"""Start the uber basic interface.
All request are handled by BasicWeb method handle_request.
"""
def make_handler(parent):
class RequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
# A super-simple HTTP request handler:
def do_GET(self):
parent.handle_request("GET", self)
def do_POST(self):
parent.handle_request("POST", self)
def do_PUT(self):
parent.handle_request("PUT", self)
def do_DELETE(self):
parent.handle_request("DELETE", self)
def do_HEAD(self):
parent.handle_request("HEAD", self)
return RequestHandler
self.log.info("Creating FakeWebServer.")
self.server = StoppableTCPServer((self.interface, self.port), make_handler(self))
def _start(data=0):
self.log.info("start: URI<%s>" % self.uri)
self.server.serve_forever()
thread.start_new(_start, (0,))
示例6: __init__
def __init__(self, bot, config):
self.bot = bot
self.config = config
self.about = "Eggdropbot allows sleekbots to run Eggdrop IRC (TCL) scripts, providing the (currently partial) Eggdrop API re-implemented for XMPP MUC.\nWritten By: Kevin Smith"
self.bot.addIMCommand('eggdrop', self.handle_eggdrop)
self.bot.addMUCCommand('eggdrop', self.handle_eggdrop)
self.bot.addHelp('eggdrop', 'Eggdrop control command', "Configure eggdrop compatability support.", 'eggdrop [args]')
self.bot.add_event_handler("message", self.handle_message_event, threaded=True)
self.bot.add_event_handler("groupchat_message", self.handle_muc_event, threaded=True)
# queue of outgoing TCL
self.queue = Queue.Queue()
# list of incoming messages from tcl
self.messageQueue = []
#self.queueExec('puts "bert"')
#TCL support scripts - these are the TCL side of the eggdrop emulation
self.queueExec('source "plugins/eggdrop/support.tcl"')
self.queueExec('source "plugins/eggdrop/eggdropcompat.tcl"')
#load the user-specified eggdrop scripts
scripts = self.config.findall('script')
if scripts:
for script in scripts:
logging.info("eggdropbot.py loading script %s." % script.attrib['file'])
self.queueExec('source "scripts/' + script.attrib['file'] + '"')
thread.start_new(self.loop,())
示例7: run
def run():
try:
insert_iptables_rules()
thread.start_new(handle_nfqueue, ())
except:
LOGGER.exception('failed to start dns service')
dns_service_status.error = traceback.format_exc()
示例8: applyFunctionToNFrames
def applyFunctionToNFrames(func, filesPerThread, nframes, conversionargs):
if(nframes < filesPerThread):
func(0, 0, nframes, conversionargs)
else:
try:
import thread
keepSpawning = 1
start = filesPerThread
end = filesPerThread
threadID = 1
# Create a mutex array
numThreads = nframes / filesPerThread
if(numThreads * filesPerThread < nframes):
numThreads = numThreads + 1
exitmutex = [0] * numThreads
while keepSpawning == 1:
end = end + filesPerThread
if(end >= nframes):
end = nframes
keepSpawning = 0
thread.start_new(applyFunctionToNFramesWMutex, (threadID, exitmutex, func, start, end, conversionargs))
start = start + filesPerThread
threadID = threadID + 1
# Do the first part of the work on the main thread.
applyFunctionToNFramesWMutex(0, exitmutex, func, 0, filesPerThread, conversionargs)
# Wait for all of the threads to complete
while 0 in exitmutex: pass
except ImportError:
print "Could not import threads module."
func(0, 0, nframes, conversionargs)
示例9: pressStart
def pressStart(self):
'''
Function triggered by clicking 'START' button.
It will start a new thread to simulate the streaming fashion.
'''
thread.start_new(self.runForever, ());
self.start_btn['state'] = Tkinter.DISABLED;
示例10: __init__
def __init__(self, bot, config):
self.bot = bot
self.config = config
self.about = "Attempts to keep Sleek in muc channels."
self.shuttingDown = False
thread.start_new(self.loop, ())
self.bot.add_handler("<message xmlns='jabber:client' type='error'><error type='modify' code='406' ><not-acceptable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></message>", self.handle_message_error)
示例11: test_fork
def test_fork(self):
# XXX This test depends on a multicore machine, as busy_thread must
# aquire the GIL the instant that the main thread releases it.
# It will incorrectly pass if the GIL is not grabbed in time.
import thread
import os
import time
if not hasattr(os, 'fork'):
skip("No fork on this platform")
run = True
done = []
def busy_thread():
while run:
time.sleep(0)
done.append(None)
try:
thread.start_new(busy_thread, ())
pid = os.fork()
if pid == 0:
os._exit(0)
else:
time.sleep(1)
spid, status = os.waitpid(pid, os.WNOHANG)
assert spid == pid
finally:
run = False
self.waitfor(lambda: done)
示例12: resolveFakeDimensions
def resolveFakeDimensions (self, task):
netCdfObject = GmiNetCdfFileTools ()
print "about to start threads for resolving dimensions..."
exitMutexes = []
count = 0
for prefix in self.PREFIXES:
for resolution in ["2x2.5", "1x1.25", "0.625x0.5"]:
fileName = self.basePath + prefix + self.endPath + "." + resolution + ".nc"
if not os.path.exists (fileName): raise fileName + " does not exist! ERROR"
# for each file type fix the fake dimensions
exitMutexes.append (thread.allocate_lock())
thread.start_new (netCdfObject.resolveFieldDimensions, \
(fileName, count, self.GEOS5FIELDS, ['time', 'lat', 'lon'], exitMutexes[count]))
count = count + 1
#----------------------------------------------------------------
# Wait for all three threads before proceeding
#----------------------------------------------------------------
for mutex in exitMutexes:
while not mutex.locked ():
pass
print "All threads returned from resolveFieldDimensions"
示例13: __init__
def __init__(self, serverIP, port=8000, autoEvents=True):
utils.logger.debug("RClient.__init__")
synchronized.Synchronized.__init__(self)
dMVC.setRClient(self)
self.__serverIP = serverIP
self.__serverPort = port
self.__rootModel = None
self.__sessionID = None
self.__version = None
self.__initialDataSemaphore = threading.Semaphore(0)
self.__answersCommandsList = []
self.__remoteSuscriptions = {}
self.__socket = None
self.__connect()
self.__commandQueue = Queue.Queue()
self.__asyncCommandQueue = Queue.Queue()
self.__asyncCallback = {}
self.__fragmentAnswer = {}
self.__autoEvents = autoEvents
if self.__autoEvents:
threadProcessCommand = threading.Thread(target=self.processCommandQueue)
threadProcessCommand.setDaemon(True)
threadProcessCommand.start()
thread.start_new(self.__start, ())
示例14: parent
def parent():
i = 0
while 1:
i = i + 1
thread.start_new(child, (i,))
if raw_input() == "q":
break
示例15: find_url
def find_url(r, nused):
while True:
try:
for i in r["response"]["posts"]:
id = i["id"]
id = str(id)
#print id
test_url = 'http://api.tumblr.com/v2/blog/'+tumblr+'/posts?id='
test_url += str(i["id"]) + "&api_key=LavgbZzW1LV2skL5EMhhrEucUPikpP4Ag6KKNBJB77dojfzfaw"
#print test_url
testinfo = requests.get(test_url, auth=oauth).json()
for aa in testinfo["response"]["posts"]:
if 'photos' not in aa:
continue
else:
for bb in aa["photos"]:
#print bb["original_size"]["url"]
filename = str(bb["original_size"]["url"])
filename = filename.split('_', 1)[-1]
filename = os.path.join(dest_dir, filename)
while threading.activeCount() >= 100:
sleep(2)
else:
thread.start_new(download_url, (bb["original_size"]["url"], filename))
except requests.exceptions.RequestException:
global problem
problem = problem + 1
sleep(5)
continue
else:
break