rumps icon indicating copy to clipboard operation
rumps copied to clipboard

Double event loop possible?

Open ethanpil opened this issue 5 years ago • 7 comments

A simplification of my application is a web server controlled by the Rumps menu. I cannot combine Rumps main loop and asyncio (or any other similar web server lib)'s event loop. In a way that doesn't lock up the Rumps GUI.

Based on some of the examples below, (I am not much of a MacOS internals person) do you think it would be possible to add some functionality to integrate two event loops in some sort of co-routine with Rumps?

For more info, please look here: https://www.reddit.com/r/Python/comments/33ecpl/neat_discovery_how_to_combine_asyncio_and_tkinter/ https://github.com/harvimt/quamash https://pypi.org/project/async_gui/0.1.1/ https://docs.python.org/3/library/asyncio-task.html

ethanpil avatar Jun 05 '19 04:06 ethanpil

Do you have example code you have been working with? I'd like to play around with it.

jaredks avatar Jun 18 '19 22:06 jaredks

I have the same question.

I would like to use wxWidgets to create some windows, but wxWidgets event loop is brought up by app.MainLoop() and rumps also requires a App().run(). These two calls are all blocking.

Investigate a bit on rumps.App().run(): It calls AppHelper.runEventLoop(), which calls NSApp().run(), which is blocking.

https://opensource.apple.com/source/pyobjc/pyobjc-37/pyobjc/pyobjc-framework-Cocoa/Lib/PyObjCTools/AppHelper.py.auto.html

Not sure how to implement this...

BTW, thanks for creating this handy library.

xinhuang avatar Jul 18 '19 19:07 xinhuang

Yeah.. App().run() (rumps) and asyncio's event loop don't play nice together. Tried putting rumps in a Python thread, I got:

objc.error: NSInternalInconsistencyException - NSWindow drag regions should only be invalidated on the Main Thread!

<_<

sanderfoobar avatar May 05 '20 17:05 sanderfoobar

I think using two different UI packages generally isn't advised.

jaredks avatar May 09 '20 13:05 jaredks

My original issue was in regards to asyncio for web server. Same problem. I'm sorry I haven't posted up the code. I will find that and get it up soon. Thanks for your patience.

ethanpil avatar May 10 '20 03:05 ethanpil

I have a situation where this would also be handy. I'm attempting to use the python library @ https://github.com/jonathanslenders/ui24r-client to create a system tray app that monitors the mute status of channels on a mixer. The library is an asyncio-based client. The goal would be to use the client to manipulate the title of the menu bar app. I have an existing solution that updates every second using xbar, but I'm hoping to find a solution that provides real-time feedback.

belthesar avatar Jan 31 '23 03:01 belthesar

I haven't tried this, but you should be able to run the asyncio loop in a thread different from the main thread. See for example this gist: Python asyncio event loop in a separate thread

brechtm avatar Mar 08 '23 23:03 brechtm