Skip to main content

CoreFoundation based selector and asyncio event loop

Project description

CoreFoundation based selector and asyncio event loop

asyncio event loop

On macOS X, Cocoa uses an event loop to dispatch events (NSRunLoop, which is a wrapper around CFRunLoop).

Python's asyncio module uses an event loop too to handle asynchronous events. On macOS X, it's based on kqueue.

A thread can only use a single event loop, that's why it's not possible to use both Cocoa and asyncio on the same thread. This module implements an asyncio compatible event loop on top of CFRunLoop. Thus it's possible to use Cocoa in conjunction with asyncio. It uses internally PyObjC's runEventLoop or runConsoleEventLoop

Here is an example video of a simple Cocoa based GUI using asyncio and async/await to handle subprocesses and network calls:

Example video

The corresponding code is here: tests/gui/guidemo.py

Setup:

    loop = CoreFoundationEventLoop()
    asyncio.set_event_loop(loop)
    try:
        loop.run_forever()
    finally:
        loop.close()

CoreFoundationEventLoop's constructor's first argument is a boolean. True for a console app, False (default) for a GUI app. Additionnal arguments are then passed to PyObjCTools.AppHelper.runConsoleEventLoop or PyObjCTools.AppHelper.runEventLoop

selector

This module also provides a selector implementation based on CFRunLoop. But his selector isn't compatible with Cocoa GUIs

Installation

$ pip3 install corefoundationasyncio

This module depends on pyobjc

Contributing

Report issues here

Pull-requests welcome !

License

This software is licensed under the MIT license

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

corefoundationasyncio-0.0.1.tar.gz (4.6 kB view details)

Uploaded Source

File details

Details for the file corefoundationasyncio-0.0.1.tar.gz.

File metadata

  • Download URL: corefoundationasyncio-0.0.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for corefoundationasyncio-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8053494f0c7c3cb1feb35484423039fa6f4ddfe278a2cc5520d4ff2920f0ad01
MD5 882ff9d4acba84f71bae9cd24102a196
BLAKE2b-256 43ab888771f58dd20a9350e446a470eb046ee0085f0aaee198d4b4da6f5e2ec3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page