coroutine

How can I abandon a LuaJ coroutine LuaThread?

被刻印的时光 ゝ 提交于 2019-12-23 12:55:00
问题 I am experimenting with a game mechanic in which players can run scripts on in-game computers. Script execution will be resource limited at a gameplay level to some amount of instructions per tick. The following proof-of-concept demonstrates a basic level of sandboxing and throttling of arbitrary user code. It successfully runs ~250 instructions of poorly crafted 'user input' and then discards the coroutine. Unfortunately, the Java process never terminates. A little investigation in shows

Asyncio coroutine never awaited error

混江龙づ霸主 提交于 2019-12-23 10:36:02
问题 I'm having trouble fixing and understanding the problem here. I'm using an example to learn Asyncio but the code I'm using is similar to mine but mine gives an error message saying: sys:1: RuntimeWarning: coroutine 'run_script' was never awaited Please any help will be greatly appreciated. Below is my code async def run_script(script): print("Run", script) await asyncio.sleep(1) os.system("python " + script) and I'm running it like this for script in os.listdir(): if script.endswith(".py"):

Asyncio coroutine never awaited error

北城以北 提交于 2019-12-23 10:35:11
问题 I'm having trouble fixing and understanding the problem here. I'm using an example to learn Asyncio but the code I'm using is similar to mine but mine gives an error message saying: sys:1: RuntimeWarning: coroutine 'run_script' was never awaited Please any help will be greatly appreciated. Below is my code async def run_script(script): print("Run", script) await asyncio.sleep(1) os.system("python " + script) and I'm running it like this for script in os.listdir(): if script.endswith(".py"):

What can cause the simple invocation of asyncio.new_event_loop() to hang?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 07:56:16
问题 I am using the following function to force a coroutine to run synchronously: import asyncio import inspect import types from asyncio import BaseEventLoop from concurrent import futures def await_sync(coro: types.CoroutineType, timeout_s: int=None): """ :param coro: a coroutine or lambda loop: coroutine(loop) :param timeout_s: :return: """ loop = asyncio.new_event_loop() # type: BaseEventLoop if not is_awaitable(coro): coro = coro(loop) if timeout_s is None: fut = asyncio.ensure_future(coro,

produce<Type> vs Channel<Type>()

删除回忆录丶 提交于 2019-12-23 05:04:21
问题 Trying to understand channels. I want to channelify the android BluetoothLeScanner. Why does this work: fun startScan(filters: List<ScanFilter>, settings: ScanSettings = defaultSettings): ReceiveChannel<ScanResult?> { val channel = Channel<ScanResult>() scanCallback = object : ScanCallback() { override fun onScanResult(callbackType: Int, result: ScanResult) { channel.offer(result) } } scanner.startScan(filters, settings, scanCallback) return channel } But not this: fun startScan(scope:

How did the game developer of 2048 made their tiles to move smoothly ? see the detail below

余生长醉 提交于 2019-12-22 12:08:28
问题 I have made the complete copy of 2048 game but i have moved by tiles by teleporting (no smoothness moving of tiles like it was in original game) I have used the following code for smothness of moving tiles. //GameManager script void MoveRight () { //some code .. AnimateTileMovement (newPosition); // newposition is the position to whihc the tiles is going to move //some code which i need to execute (ONLY AFTER MY COMPLETE MOVEMENT OF TILE) // BUT AS SOON AS TileMovement return its first null

Blocking calls with Gevent and WSGI

安稳与你 提交于 2019-12-22 11:11:48
问题 I've just started working with coroutines and have read up on gevent and greenlets. For a test I served this code through gevents pywsgi module: from gevent.pywsgi import WSGIServer import gevent def hello_world(env, start_response): gevent.sleep(5) start_response('200 OK', [('Content-Type', 'text/html')]) return ["<b>hello world</b>"] print 'Serving on 8088...' WSGIServer(('127.0.0.1', 8888), hello_world).serve_forever() I expected a result where every request would get a 5 second delay

Can't catch exception throwing after Kotlin coroutine is cancelled

一世执手 提交于 2019-12-22 10:49:36
问题 Using kotlinx.coroutines lib I can't catch an exception if it was thrown after coroutine is canceled. This leads to app crash. fun foo() { val job = launch(UI) { try { Log.d("TAG", "Start coroutine") run(CommonPool) { Log.d("TAG", "Start bg task") // Intentionally make bg task running for a long time SystemClock.sleep(2000) Log.d("TAG", "Throw bg task exception") throw RuntimeException("Bg task exception") } } catch (e: Exception) { Log.e("TAG", "Handle coroutine exception", e) } } launch(UI)

Better way than using `Task/produce/consume` for lazy collections express as coroutines

不想你离开。 提交于 2019-12-22 08:13:32
问题 It is very convenient to use Tasks to express a lazy collection / a generator. Eg: function fib() Task() do prev_prev = 0 prev = 1 produce(prev) while true cur = prev_prev + prev produce(cur) prev_prev = prev prev = cur end end end collect(take(fib(), 10)) Output: 10-element Array{Int64,1}: 1 1 2 3 5 8 13 21 34 However, they do not follow good iterator conventions at all. They are as badly behaved as they can be They do not use the returned state state start(fib()) == nothing #It has no state

Why do we need coroutines in python? [closed]

北战南征 提交于 2019-12-22 08:07:55
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I've heard about co-routines long ago, but never used them. As I know, co-routines are similar to generators. Why do we need co-routines in Python? 回答1: Generator uses yield to return values. Python generator functions can also consume values using a (yield) statement. In addition