本文整理汇总了Python中multiprocessing.Queue.put_nowait方法的典型用法代码示例。如果您正苦于以下问题:Python Queue.put_nowait方法的具体用法?Python Queue.put_nowait怎么用?Python Queue.put_nowait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.Queue
的用法示例。
在下文中一共展示了Queue.put_nowait方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LoggingServer
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import put_nowait [as 别名]
class LoggingServer(Process, UDPServer):
def __init__ (self):
from app import APP
port = APP.BE.LOGGING._i_server_port
UDPServer.__init__(self, ('127.0.0.1', port), None)
Process.__init__ (self, None, None, "pcLOG" )
self.queue = Queue( APP.BE.LOGGING._i_queue_size )
self.backend = LoggingBackend (self.queue)
self.backend.start()
self.on = True
self.start()
def finish_request(self, request, client_address):
from app import APP
APP.Functions.set_process_name ( "[email protected]@LOG" )
data, sock = request
try:
(src, svr,msg) = cPickle.loads ( data )
self.queue.put_nowait ( (time.time(), src,svr,msg) )
if src is None: self.on = False
except ThQueue.Full:
print "Full"
except:
pass
def run(self):
while self.on:
self.handle_request()
self.queue.put ( (None, None, None, None) )
示例2: __init__
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import put_nowait [as 别名]
class IOBase:
def __init__(self, bus):
self.bus = bus
self.bus.subscribe(self.process_event, thread=False)
self.write_queue = Queue(10)
self.reader = threading.Thread(target=self.reader_thread)
self.reader.daemon = True
self.reader.start()
self.writer = threading.Thread(target=self.writer_thread)
self.writer.daemon = True
self.writer.start()
def reader_thread(self):
raise NotImplementedError()
def writer_thread(self):
raise NotImplementedError()
def convert_data(self, data):
return data
def process_event(self, ev):
try:
if ev.name == "leds_enabled":
data = self.convert_data(ev.data)
self.write_queue.put_nowait(data)
except queue.Full:
# TODO alert somehow without flooding?
pass
示例3: videoCallback
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import put_nowait [as 别名]
def videoCallback( frame, robot=None, debug=False ):
global g_queueOut, g_processor
if g_queueOut is None:
g_queueOut = Queue()
g_processor = Process( target=processMain, args=(g_queueOut,) )
g_processor.daemon = True
g_processor.start()
g_queueOut.put_nowait( frame ) # H264 compressed video frame
示例4: MutationTestRunnerProcess
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import put_nowait [as 别名]
class MutationTestRunnerProcess(MutationTestRunner, Process):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.queue = Queue()
def get_result(self, live_time):
try:
return self.queue.get(timeout=live_time)
except Empty:
return None
def set_result(self, result):
self.queue.put_nowait(result.serialize())
示例5: main
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import put_nowait [as 别名]
def main():
files_to_download = Queue()
with open('downloads.txt', 'r') as f:
for to_download in f:
files_to_download.put_nowait(to_download.split('\n')[0])
print("=== puremultiprocessing ===")
total_processors = cpu_count()
start = datetime.datetime.now()
jobs = []
for i in range(total_processors):
p = Process(target = download, args=(files_to_download,))
jobs.append(p)
p.start()
for j in jobs:
j.join()
print("{0} took {1} seconds to complete all downloads".format(__file__,\
datetime.datetime.now() - start))
示例6: SpectrumLightController
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import put_nowait [as 别名]
class SpectrumLightController(object):
def __init__(self, sampleGen):
self.sampleGen = sampleGen
sampleGen.onSample.add(self._onSample)
sampleGen.onSongChanged.add(self._onSongChanged)
atexit.register(self._onExit)
self.messageQueue = Queue()
self.process = Process(target=self.lightControllerProcess, args=(self.messageQueue, ))
self.process.start()
def _onSongChanged(self):
try:
self.messageQueue.put_nowait(('songChange', self.sampleGen.currentFilename))
except QueueFull:
ansi.error("Message queue to light process full! Continuing...")
def _onSample(self):
try:
self.messageQueue.put_nowait(('chunk', self.sampleGen.currentData))
except QueueFull:
ansi.error("Message queue to light process full! Continuing...")
def _onExit(self):
if self.process.is_alive():
try:
self.messageQueue.put(('end', ))
except QueueFull:
ansi.error("Message queue to light process full! Continuing...")
@staticmethod
def lightControllerProcess(messageQueue):
import lights
if lightProcessNice:
os.nice(lightProcessNice)
analyzer = lights.SpectrumAnalyzer(messageQueue, gcp)
analyzer.loop()
示例7: BlockingQueueGenerator
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import put_nowait [as 别名]
class BlockingQueueGenerator(object):
"""
Provides a generator that utilizes a bounded, blocking queue to store objects. Useful for async sourcing agents
that need provide a stream of objects over time as a generator.
"""
def __init__(self, maxsize=1000):
self._data = Queue(maxsize=maxsize)
def __iter__(self):
return self
def __next__(self):
return self.next()
def next(self):
return self._data.get(block=True)
def emit(self, obj):
self._data.put_nowait(obj)
示例8: __init__
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import put_nowait [as 别名]
class SafeQueue:
""" Safe Queue implementation is a wrapper around standard multiprocessing
queue. Implements safe queuing and dequeueing. """
def __init__(self, size=10):
self._queue = Queue(size)
self._lock = Lock()
def queue(self, inp):
self._lock.acquire()
if self._queue.full():
self._queue.get()
self._queue.put_nowait(inp)
self._lock.release()
def dequeue(self):
self._lock.acquire()
item = None
if not self._queue.empty():
item = self._queue.get_nowait()
self._lock.release()
return item
示例9: __init__
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import put_nowait [as 别名]
class GameClient:
def __init__(self, server_addres):
self.socket = None
self.message_queue = Queue()
self.event_queue = Queue()
self.server_addres = server_addres
self.pygame_client = None
async def connect(self):
session = ClientSession()
self.socket = await session.ws_connect(self.server_addres)
log.info('connected')
async def handle_messages(self):
while True:
message = await self.socket.receive_json()
self.message_queue.put_nowait(message)
await asyncio.sleep(TIME_STEP)
async def handle_events(self):
while True:
try:
event = self.event_queue.get_nowait()
self.socket.send_json(event)
except Empty:
await asyncio.sleep(TIME_STEP)
def spawn_drawer_process(self):
self.pygame_client.initialize_screen()
Process(target=self.pygame_client.run).start()
def run(self, loop=None):
self.pygame_client = PygameClient(self.message_queue, self.event_queue)
self.spawn_drawer_process()
loop = loop or asyncio.get_event_loop()
loop.run_until_complete(self.connect())
loop.create_task(self.handle_events())
loop.create_task(self.handle_messages())
loop.run_forever()
示例10: SpectrumLightController
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import put_nowait [as 别名]
class SpectrumLightController(object):
def __init__(self, sampleGen):
self.sampleGen = sampleGen
sampleGen.onSample.add(self._onSample)
sampleGen.onSongChanged.add(self._onSongChanged)
atexit.register(self._onExit)
if useGPIO:
import lights_gpio as lights
else:
import lights
self.messageQueue = Queue()
self.subProcess = Process(target=lights.runLightsProcess, args=(self.messageQueue, ))
self.subProcess.start()
def _onSongChanged(self, tags, songInfo):
try:
self.messageQueue.put_nowait(('songChange', self.sampleGen.currentFilename, songInfo))
except QueueFull:
ansi.error("Message queue to light process full! Continuing...")
def _onSample(self, data):
try:
if isinstance(data, buffer):
data = bytes(data)
self.messageQueue.put_nowait(('chunk', data))
except QueueFull:
ansi.error("Message queue to light process full! Continuing...")
def _onExit(self):
if self.subProcess.is_alive():
try:
self.messageQueue.put(('end', ))
except QueueFull:
ansi.error("Message queue to light process full! Continuing...")
示例11: Window
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import put_nowait [as 别名]
class Window(Borg):
def __init__(self, width, height):
super(Window, self).__init__()
self._draw_queue = Queue()
self._input_queue = Queue()
self._window = _GameWindow(width, height, self._draw_queue, self._input_queue)
self._window.start()
def blit(self, source, dest, area=None, special_flags = 0):
self._draw_queue.put_nowait([pygame.image.tostring(source, "RGBA"),
source.get_width(), source.get_height(),
dest, area, special_flags])
def quit(self):
self._window.quit.value = True
self._window.join()
@property
def events(self):
if not self._input_queue.empty():
return self._input_queue.get()
else:
return []
示例12: FileController
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import put_nowait [as 别名]
class FileController(Thread):
def __init__(self, period):
Thread.__init__(self)
self.daemon = True
self.cnt = 0
self.period = period
self.que = Queue(1024*8)
self.dorun = True
def run(self):
while (self.dorun):
time.sleep(self.period)
tm = dt.datetime.now().strftime('%Y%m%d_%H.log')
with open(tm, 'a') as f:
while (self.que.empty() == False):
entry = self.getNext()
self.writeFile(f, entry)
f.closed
def writeFile(self, file, entry):
file.write('{}\n'.format(entry))
def stopit(self):
self.dorun = False
def getNext(self):
try:
return self.que.get(True, timeout=60)
except:
print("Exception")
def read_queue(self):
yield self.que.get(True, None)
def putNext(self, entry):
self.que.put_nowait(entry)
示例13: getNewPicture
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import put_nowait [as 别名]
def getNewPicture( firstInit ):
global g_queueOut, g_processor, g_queueResults
if g_queueOut is None:
g_queueOut = Queue()
g_queueResults = Queue()
g_processor = Process( target=processMain, args=(g_queueOut,g_queueResults,) )
g_processor.daemon = True
g_processor.start()
if firstInit:
g_queueOut.put_nowait( 1 )
return None
elif firstInit is None:
g_queueOut.put_nowait( None )
time.sleep(1)
g_queueOut = None
else:
if g_queueResults.empty():
return None
ret = g_queueResults.get()
g_queueOut.put_nowait( 1 )
return ret
示例14: __init__
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import put_nowait [as 别名]
class ComponentDriver:
class RESPONSE:
Callback = 0
Error = 1
def __init__(self, name, component_main, keep_alive_always=False, keep_alive_when_outgoing=False):
self.name = name
self.component_main = component_main
self.keep_alive_always = keep_alive_always
self.keep_alive_when_outgoing = keep_alive_when_outgoing
self.to_component = Queue()
self.from_component = Queue()
self.proc = None
self.proc_counter = 0
self.kickstart()
thread = threading.Thread(target=self.main_loop)
thread.setDaemon(True)
thread.start()
if self.keep_alive_always or self.keep_alive_when_outgoing:
thread = threading.Thread(target=self.keepalive_loop)
thread.setDaemon(True)
thread.start()
signal_component.connect(self.receive, weak=False)
def kickstart(self):
curr_proc_counter = self.proc_counter
self.proc_counter += 1
try:
shutdown.disconnect(self.proc.dispatch_uid)
except:
pass
try:
self.proc.terminate()
except:
pass
self.proc = Process(target=self.component_main, args=(self.to_component, self.from_component))
self.proc.daemon = True
self.proc.start()
# Daemon flag seems not to work, so do this
curr_proc = self.proc
curr_proc.dispatch_uid = curr_proc_counter
def terminate_proc(sender, **kwargs):
if curr_proc.is_alive():
try:
if WINDOWS:
curr_proc.terminate()
else:
os.kill(curr_proc.pid, signal.SIGKILL) # Stronger method
except:
pass
shutdown.connect(terminate_proc, weak=False, dispatch_uid=curr_proc_counter)
def main_loop(self):
while True:
response_type, data = self.from_component.get()
if response_type == ComponentDriver.RESPONSE.Callback:
callback, param = data
CModule.run_script('Tools.callbacks.tryCall("%s", "%s")' % (callback, param))
elif response_type == ComponentDriver.RESPONSE.Error:
CModule.show_message('Error', 'Component %s: %s' % (self.name, data))
def keepalive_loop(self):
while True:
time.sleep(1.0)
# Restart
if not self.proc.is_alive() and (self.keep_alive_always or (self.keep_alive_when_outgoing and not self.to_component.empty())):
self.kickstart()
continue
def receive(self, sender, **kwargs):
component_id = kwargs['component_id']
data = kwargs['data']
try:
if component_id == self.name:
parts = data.split('|')
command = parts[0]
params = '|'.join(parts[1:])
self.to_component.put_nowait((command, params))
except Exception, e:
log(logging.ERROR, "Error in %s component: %s" + (self.name, str(e)))
return ''
示例15: Value
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import put_nowait [as 别名]
if i==starttime+1000:
pub_gamma.publish(1)
caption_queue.put_nowait('STIM right')
if i==starttime+1500:
pub_gamma.publish(0)
caption_queue.put_nowait('STIM off')
if i==starttime+2000:
break
rospy.sleep(0.01)
i += 1
pub_gamma.publish(0)
if __name__ == "__main__":
timestamp_shmem = Value('L', 0L, lock=False)
caption_queue = Queue()
caption_queue.put_nowait('preparing')
save_queue = Queue()
save_thread_stop_requested = multiprocessing.Event()
save_thread = multiprocessing.Process(target=save_frames, args=(save_queue,save_thread_stop_requested))
save_thread.start()
grab_thread_stop_requested = multiprocessing.Event()
grab_thread = multiprocessing.Process(target=grab_frames, args=(0,12,32, save_queue, caption_queue, timestamp_shmem, grab_thread_stop_requested))
grab_thread.start()
do_experiment(caption_queue, timestamp_shmem)
print 'Asking grabbing process to stop'
grab_thread_stop_requested.set()
grab_thread.join()