Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

np.errstate is not asyncio-safe #9444

Closed
Labels
@eric-wieser

Description

@eric-wieser

While it is threadsafe, thewith statement gives the false impression that it's always safe. It is not:

importasyncioimportnumpyasnpdefdivide_by_zero():np.float64(1)/0asyncdeffoo():forjinrange(3):withnp.errstate(divide='raise'):foriinrange(2):try:divide_by_zero()exceptFloatingPointError:passelse:print("foo: Failed to raise!")awaitasyncio.sleep(0.15)asyncdefbar():forjinrange(3):withnp.errstate(divide='ignore'):foriinrange(2):try:divide_by_zero()exceptFloatingPointError:print("bar: raised anyway!")awaitasyncio.sleep(0.11)loop=asyncio.get_event_loop()loop.run_until_complete(asyncio.gather(foo(),bar()))loop.close()

gives:

foo: Failed to raise!bar: raised anyway!foo: Failed to raise!

because the error-state is thread-local, but asyncio tasks share a thread.

I don't know if there is any way this can be fixed - it seems like this might be a python bug, and context managers might need an__yield_enter__ and__yield_leave__ mechanism, to be notified when control is leaving the suite via ayield/await

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp