How to use the janus.Queue function in janus

To help you get started, we’ve selected a few janus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aio-libs / janus / tests / test_async.py View on Github external
async def test_blocking_get(self):
        _q = janus.Queue()
        q = _q.async_q
        q.put_nowait(1)

        res = await q.get()
        self.assertEqual(1, res)

        self.assertFalse(_q._sync_mutex.locked())
        _q.close()
        await _q.wait_closed()
github aio-libs / janus / tests / test_async.py View on Github external
async def test_nonblocking_get(self):
        _q = janus.Queue()
        q = _q.async_q
        q.put_nowait(1)
        self.assertEqual(1, q.get_nowait())

        _q.close()
        await _q.wait_closed()
github aio-libs / janus / tests / test_async.py View on Github external
async def test_float_maxsize(self):
        _q = janus.Queue(maxsize=1.3)
        q = _q.async_q
        q.put_nowait(1)
        q.put_nowait(2)
        self.assertTrue(q.full())
        self.assertRaises(asyncio.QueueFull, q.put_nowait, 3)

        _q.close()
        await _q.wait_closed()

        _q = janus.Queue(maxsize=1.3)
        q = _q.async_q

        async def queue_put():
            await q.put(1)
            await q.put(2)
            self.assertTrue(q.full())

        await queue_put()

        self.assertFalse(_q._sync_mutex.locked())
        _q.close()
        await _q.wait_closed()
github tiotdev / steem-curationbot / curationbot.py View on Github external
except:
                                logger.warning("Could not promote advertisement post by @{}".format(author))
                            adfile.close()
                            adfile = open(autpath, 'a+')
            except ContentDoesNotExistsException:
                continue
            except Exception as error:
                logger.warning("Exception during post processing: "+repr(error))
                continue

if __name__ == '__main__':
    """
    Starting the bot. An optional custom starting block can be defined in the optional *startblock* file.
    """
    loop = asyncio.get_event_loop()
    queue = janus.Queue(loop=loop) #janus enables the synchronous beem library to work with the asynchronous Discord.py library
    actionqueue = queue.sync_q
    loop.create_task(stream_history())
    loop.create_task(stream_rewards(None))
    loop.create_task(claim_accounts())
    loop.create_task(queue_worker(actionqueue))
    threaded = loop.run_in_executor(None, stream_comments, actionqueue)
    while True:
        try:
            loop.run_until_complete(bot.start(TOKEN))
            loop.run_until_complete(threaded)
        except KeyboardInterrupt:
            loop.close()
            bot.logout()
            logger.debug("Bot ended by user")
            break
        except SystemExit:
github lablup / backend.ai-agent / src / ai / backend / kernel / python / __init__.py View on Github external
async def init_with_loop(self):
        self.input_queue = janus.Queue(loop=self.loop)
        self.output_queue = janus.Queue(loop=self.loop)

        # We have interactive input functionality for query mode!
        self._user_input_queue = janus.Queue(loop=self.loop)
        self.user_input_queue = self._user_input_queue.async_q

        # Get USER_SITE for runtime python.
        cmd = [self.runtime_path, *DEFAULT_PYFLAGS,
               '-c', 'import site; print(site.USER_SITE)']
        proc = await asyncio.create_subprocess_exec(
            *cmd, env=self.child_env,
            stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
        stdout, _ = await proc.communicate()
        user_site = stdout.decode('utf8').strip()
        self.child_env['PYTHONPATH'] = user_site

        # Add support for interactive input in batch mode by copying
        # sitecustomize.py to USER_SITE of runtime python.
        sitecustomize_path = Path(os.path.dirname(__file__)) / 'sitecustomize.py'
        user_site = Path(user_site)
github Azure / azure-iot-sdk-python / azure-iot-device / azure / iot / device / iothub / aio / async_inbox.py View on Github external
def __init__(self):
        """Initializer for AsyncClientInbox."""
        self._queue = janus.Queue()
github oeway / ImJoy-Engine / imjoy / worker_template.py View on Github external
if "" not in sys.path:
        sys.path.insert(0, "")

    imjoy_path = os.path.dirname(os.path.normpath(__file__))
    if imjoy_path not in sys.path:
        sys.path.insert(0, imjoy_path)

    logging.basicConfig(stream=sys.stdout)
    logger.setLevel(logging.INFO)
    if opt.debug:
        logger.setLevel(logging.DEBUG)

    if PYTHON3:
        event_loop = asyncio.get_event_loop()
        job_queue = janus.Queue(loop=event_loop)
    else:
        event_loop = None
        job_queue = None

    plugin_conn = PluginConnection(
        opt.id,
        opt.secret,
        opt.server,
        job_queue=job_queue,
        loop=event_loop,
        worker=task_worker,
        work_dir=opt.work_dir,
        daemon=opt.daemon,
    )
    plugin_conn.wait_forever()
github oeway / ImJoy-Engine / imjoy / workers / python3_client.py View on Github external
def __init__(self, id=None):
        """Set up client instance."""
        super().__init__(id)
        self.loop = asyncio.get_event_loop()
        self.janus_queue = janus.Queue(loop=self.loop)
        self.queue = self.janus_queue.sync_q
        self.task_worker = task_worker
github lablup / backend.ai-agent / src / ai / backend / kernel / r / __init__.py View on Github external
async def init_with_loop(self):
        self.input_queue = janus.Queue(loop=self.loop)
        self.output_queue = janus.Queue(loop=self.loop)

        # We have interactive input functionality!
        self._user_input_queue = janus.Queue(loop=self.loop)
        self.user_input_queue = self._user_input_queue.async_q