Skip to content

asyncio-related shutdown problem, "Future object is not initialized." #273

Closed

Description

@wesgarland

Issue type

Bug

How did you install PythonMonkey?

Source

OS platform and distribution

No response

Python version (python --version)

3.10.12

PythonMonkey version (pip show pythonmonkey)

0.3.1.dev42+6b5fb9d

Bug Description

This program will crash with a segfault:

#! /usr/bin/env python3

import pythonmonkey as pm

async def go():
    dcpConfig = pm.globalThis.dcpConfig
    Connection = pm.globalThis.dcp.protocol.Connection
    target = dcpConfig.scheduler.services.jobSubmit
    conn = pm.new(Connection)(target)
    await conn.connect()        
    quit()

dcp_client = pm.require('dcp-client/index.py') # should be just dcp-client, see pm issue 247
dcp_client['init'](go)

The error is:

[~/git2/python-launch-job] dev-wes:wes# ./kaboom.py 
Traceback (most recent call last):
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 636, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.10/asyncio/base_events.py", line 603, in run_forever
    self._run_once()
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1909, in _run_once
    handle._run()
  File "/usr/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/wes/git2/python-launch-job/node_modules/dcp-client/index.py", line 60, in load_dcp_client
    cb_retval = await callback()
  File "/home/wes/git2/python-launch-job/./kaboom.py", line 11, in go
    quit()
  File "/usr/lib/python3.10/_sitebuiltins.py", line 26, in __call__
    raise SystemExit(code)
SystemExit: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/wes/git2/python-launch-job/./kaboom.py", line 14, in <module>
    dcp_client['init'](go)
  File "/home/wes/git2/python-launch-job/node_modules/dcp-client/index.py", line 67, in init
    asyncio.run(load_dcp_client(callback))
  File "/usr/lib/python3.10/asyncio/runners.py", line 47, in run
    _cancel_all_tasks(loop)
  File "/usr/lib/python3.10/asyncio/runners.py", line 68, in _cancel_all_tasks
    if task.exception() is not None:
asyncio.exceptions.InvalidStateError: Future object is not initialized.
Segmentation fault (core dumped)

Removing the quit causes it to hang forever, until you hit ^C, in which case you get basically the same error stack but no segfault.

### What branch of PythonMonkey were you developing on? (If applicable)

wes/DCP-4054/make-dcp-client-grok-pythonmonkey

Activity

  1. wesgarland commented on Mar 9, 2024

    @wesgarland
    CollaboratorAuthor

    What's interesting is that my standalone XHR demo program doesn't cause any problems

    This suggests that it could be outstanding timers triggering the issue. dcp-client uses a ton of those.

  2. philippedistributive commented on Mar 13, 2024

    @philippedistributive
    Contributor

    @wesgarland any core dump/stack trace lying around?

  3. wesgarland commented on Mar 14, 2024

    @wesgarland
    CollaboratorAuthor

    Sorry, no. There's a kernel extension on my container intercepting my core dumps, and I don't want to reboot it to get rid of it until Jack is back at work. Because if I doesn't come back up I can't fix it.

  4. moved this from Backlog to Ready To Do in PythonMonkey Kanban Boardon Mar 14, 2024
  5. moved this from Ready To Do to In progress in PythonMonkey Kanban Boardon Mar 14, 2024
  6. moved this from In progress to In review in PythonMonkey Kanban Boardon Mar 14, 2024
  7. moved this from In review to In progress in PythonMonkey Kanban Boardon Mar 20, 2024
  8. added this to the v1.0.0 milestone on Apr 4, 2024
  9. philippedistributive commented on Apr 4, 2024

    @philippedistributive
    Contributor

    from @Xmader in slack:

    The error is because when calling quit() there're still some background jobs running. It cannot be fixed directly in PythonMonkey but we need to see how to properly cancel the background timers in DCP.

  10. wesgarland commented on Apr 10, 2024

    @wesgarland
    CollaboratorAuthor

    We are not changing how DCP handles timers.

    This is why we are supposed to copy the node references API stuff for PythonMonkey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions