本文将分享异步CancelledError和KeyboardInterrupt的详细内容,并且还将对异步task进行详尽解释,此外,我们还将为大家带来关于C3P0:java.lang.Interrup
本文将分享异步CancelledError和KeyboardInterrupt的详细内容,并且还将对异步task进行详尽解释,此外,我们还将为大家带来关于C3P0:java.lang.InterruptedException: sleep interrupted、Centos7 使用 YUM 进行 install 或 update 出现 KeyboardInterrupt 错误、Cython,Python和KeyboardInterrupt被忽略、DELETE_FAILED_INTERNAL_ERROR和INSTALL_CANCELED_BY_USER异常的相关知识,希望对你有所帮助。
本文目录一览:- 异步CancelledError和KeyboardInterrupt(异步task)
- C3P0:java.lang.InterruptedException: sleep interrupted
- Centos7 使用 YUM 进行 install 或 update 出现 KeyboardInterrupt 错误
- Cython,Python和KeyboardInterrupt被忽略
- DELETE_FAILED_INTERNAL_ERROR和INSTALL_CANCELED_BY_USER异常
异步CancelledError和KeyboardInterrupt(异步task)
我正在尝试2种方法来阻止无限循环运行:
- supervisor_1 :任务编程取消
- Supervisor_2 :使用Ctrl + C停止任务
虽然 supervisor_2 不会引发中断时,在任何错误,我不能让 supervisor_1 从得到Task was destroyedbut it is pending!
。知道为什么吗?
这是代码:
import asyncioimport aioredisfrom functools import partialclass Listener: def __init__(self, redis_conn): self.redis_conn = redis_conn async def forever(self, loop_name): counter = 0 try: while True: print(''{}: {}''.format(loop_name, counter)) counter += 1 await asyncio.sleep(1) except asyncio.CancelledError: print(''Task Cancelled'') self.redis_conn.close() await self.redis_conn.wait_closed()async def supervisor_1(redis_conn): redis_conn = await redis_conn l = Listener(redis_conn) task = asyncio.ensure_future( asyncio.gather(l.forever(''loop_1''), l.forever(''loop_2''))) await asyncio.sleep(2) task.cancel()async def supervisor_2(redis_conn): redis_conn = await redis_conn l = Listener(redis_conn) await asyncio.gather(l.forever(''loop_1''), l.forever(''loop_2''))if __name__ == ''__main__'': redis_conn = aioredis.create_pool((''localhost'', 5003), db=1) loop = asyncio.get_event_loop() run = partial(supervisor_2, redis_conn=redis_conn) task = asyncio.ensure_future(run()) try: loop.run_until_complete(task) except KeyboardInterrupt: print(''Interruped !'') task.cancel() loop.run_forever() finally: loop.close()
@update :
感谢@Gerasimov,这是一个可以解决此问题的版本,但仍会不时在KeyboardInterrupt上引发错误:
async def supervisor(redis_conn): redis_conn = await redis_conn l = Listener(redis_conn) task = asyncio.ensure_future( asyncio.gather(l.forever(''loop_1''), l.forever(''loop_2'')) ) await asyncio.sleep(10) task.cancel() with suppress(asyncio.CancelledError): await taskasync def kill_tasks(): pending = asyncio.Task.all_tasks() for task in pending: task.cancel() with suppress(asyncio.CancelledError): await task
和
if __name__ == ''__main__'': redis_conn = aioredis.create_pool((''localhost'', 5003), db=1) loop = asyncio.get_event_loop() run = partial(supervisor, redis_conn=redis_conn) task = asyncio.ensure_future(run()) try: loop.run_until_complete(task) except KeyboardInterrupt: print(''Interruped !'') loop.run_until_complete(kill_tasks()) finally: loop.close()
答案1
小编典典task.cancel()
本身并没有完成任务:它只是说CancelledError
应该在其中提出的任务并立即返回。您应该调用它并等待任务实际上被取消(它会引发CancelledError
)。
您也不应压制CancelledError
内部任务。
在尝试显示不同的任务处理方式的地方,请阅读此答案。例如,要取消某些任务并等待其取消,您可以执行以下操作:
from contextlib import suppresstask = ... # remember, task doesn''t suppress CancelledError itselftask.cancel() # returns immediately, we should await task raised CancelledError.with suppress(asyncio.CancelledError): await task # or loop.run_until_complete(task) if it happens after event loop stopped# Now when we awaited for CancelledError and handled it, # task is finally over and we can close event loop without warning.
C3P0:java.lang.InterruptedException: sleep interrupted
好好的就报异常了~~
警告: com.mchange.v2.resourcepool.BasicResourcePool@8fce95 -- Thread unexpectedly interrupted while performing an acquisition attempt. java.lang.InterruptedException: sleep interrupted at java.lang.Thread.sleep(Native Method) at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805) at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
Centos7 使用 YUM 进行 install 或 update 出现 KeyboardInterrupt 错误
### 错误信息
File "/usr/lib/python2.7/site-packages/urlgrabber/grabber.py", line 1517, in _do_perform
raise KeyboardInterrupt
### 解决方案 ###
### 1.打开文件:
/usr/lib/python2.7/site-packages/urlgrabber/grabber.py
### 2.在文件的1510行左右找到下面这句代码:
elif errcode in (42, 55, 56):
### 修改为:
elif errcode == 42:
### 保存退出
ESC
:wq
### 重新使用yum
Cython,Python和KeyboardInterrupt被忽略
有没有一种方法可以Ctrl+C
基于Cython扩展中嵌入的循环来中断()Python脚本?
我有以下python脚本:
def main():
# Intantiate simulator
sim = PySimulator()
sim.Run()
if __name__ == "__main__":
# Try to deal with Ctrl+C to abort the running simulation in terminal
# (Doesn't work...)
try:
sys.exit(main())
except (KeyboardInterrupt,SystemExit):
print '\n! Received keyboard interrupt,quitting threads.\n'
这会运行一个循环,该循环是C ++
Cython扩展的一部分。然后,在按Ctrl+C
的同时,将KeyboardInterrupt
引发,但将其忽略,并且程序将继续进行直到模拟结束。
我发现的解决方法是通过捕获SIGINT
信号来处理扩展中的异常:
#include <execinfo.h>
#include <signal.h>
static void handler(int sig)
{
// Catch exceptions
switch(sig)
{
case SIGABRT:
fputs("Caught SIGABRT: usually caused by an abort() or assert()\n",stderr);
break;
case SIGFPE:
fputs("Caught SIGFPE: arithmetic exception,such as divide by zero\n",stderr);
break;
case SIGILL:
fputs("Caught SIGILL: illegal instruction\n",stderr);
break;
case SIGINT:
fputs("Caught SIGINT: interactive attention signal,probably a ctrl+c\n",stderr);
break;
case SIGSEGV:
fputs("Caught SIGSEGV: segfault\n",stderr);
break;
case SIGTERM:
default:
fputs("Caught SIGTERM: a termination request was sent to the program\n",stderr);
break;
}
exit(sig);
}
然后 :
signal(SIGABRT,handler);
signal(SIGFPE,handler);
signal(SIGILL,handler);
signal(SIGINT,handler);
signal(SIGSEGV,handler);
signal(SIGTERM,handler);
我不能通过Python或至少从Cython进行这项工作吗?当我要在Windows / MinGW下移植我的扩展程序时,我希望有一些不特定于Linux的东西。
DELETE_FAILED_INTERNAL_ERROR和INSTALL_CANCELED_BY_USER异常
问题描述: Application will not run on device: INSTALL_CANCELED_BY_USER , DELETE_FAILED_INTERNAL_ERROR ?
点击确认后,运行没有成功,却在Run窗口行出现:INSTALL_CANCELED_BY_USER , DELETE_FAILED_INTERNAL_ERROR的报错问题
针对以上问题,几种解决方式(来源于网上):
-
Build –> Clean Project.
-
setting–> instant run –> 禁止开启
-
在项目的根目录中运行命令行:gradlew clean。(可以以直接在Android studio中Terminal窗口中运行该命令)
以上方法都走了一遍,结果却是无效的,犹如一万只草泥马飞奔而过。泪崩的继续找,最后锁定原因出现在手机上。
注意点:小米手机的奇葩坑,MIUI 8 开发调试要是出现: adb install失败 100%稳定复现 INSTALL_CANCELED_BY_USER。结果是小米的安全中心2.0.5版出现了问题。
解决方法: 现在小米手机上安装LBE安全大师,然后打开软件,选择软件管理–>软件卸载–>安全中心–>换成出厂设置的
版本。(来源于小米论坛)。
最终运行结果:
PS: 最近期间,走完以上步骤,发现红米Note3又发癫,调试不了。
若是上一步骤还是不行,USB调试不了,则需走一步:
安装LBE安全大师,然后打开软件,选择软件管理–>软件自动安装监控->允许自动安装
资源参考:
-
stackoverFlow上解答:http://stackoverflow.com/questions/30010388/application-will-not-run-on-device-delete-failed-internal-error
-
小米手机中以上问题解决方法来源:http://www.miui.com/thread-6953785-1-2.html
- 小米论坛解决方式:
http://www.miui.com/forum.php?mod=viewthread&tid=7466541&highlight=%E8%B0%83%E8%AF%95
今天的关于异步CancelledError和KeyboardInterrupt和异步task的分享已经结束,谢谢您的关注,如果想了解更多关于C3P0:java.lang.InterruptedException: sleep interrupted、Centos7 使用 YUM 进行 install 或 update 出现 KeyboardInterrupt 错误、Cython,Python和KeyboardInterrupt被忽略、DELETE_FAILED_INTERNAL_ERROR和INSTALL_CANCELED_BY_USER异常的相关知识,请在本站进行查询。
本文标签: