码
class A(object):
def a(self):
raise NotImplementedError
class B(A):
def a(self):
return 7
class C(B):
pass
Run Code Online (Sandbox Code Playgroud)
为什么Pycharm抱怨?
问题概要C类必须实现所有抽象方法
我有一个带有两个asyncio任务的asyncio/Python程序:
我希望我的整个程序在第一次崩溃后退出.我不能让它发生.
import asyncio
import time
def infinite_while():
while True:
time.sleep(1)
async def task_1():
await asyncio.sleep(1)
assert False
async def task_2():
loop = asyncio.get_event_loop()
await loop.run_in_executor(None, lambda: infinite_while())
loop = asyncio.get_event_loop()
asyncio.set_event_loop(loop)
tasks = asyncio.gather(task_2(), task_1())
try:
loop.run_until_complete(tasks)
except (Exception, KeyboardInterrupt) as e:
print('ERROR', str(e))
exit()
Run Code Online (Sandbox Code Playgroud)
它打印ERROR但不退出.手动关闭时,程序将打印以下堆栈跟踪:
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/usr/lib/python3.5/concurrent/futures/thread.py", line 39, in _python_exit
t.join()
File "/usr/lib/python3.5/threading.py", line 1054, in join
self._wait_for_tstate_lock()
File "/usr/lib/python3.5/threading.py", line 1070, in _wait_for_tstate_lock
elif lock.acquire(block, timeout): …Run Code Online (Sandbox Code Playgroud) 考虑以下函数
import typing
def make_list(el : typing.Any):
return [el, el]
Run Code Online (Sandbox Code Playgroud)
我如何提示它返回
typing.List[type(el)]
Run Code Online (Sandbox Code Playgroud)