FLTK logo

[fltk.general] FLTK in a secondary thread

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

FLTK in a secondary thread Rob McDonald Sep 30, 2022  
  My C++ FLTK application is wrapped with SWIG to be available form Python.  This is normally done in a non-GUI way.  We are trying to enable the GUI while keeping access via Python.

If you initialize the GUI and then start the FLTK event loop from Python, the GUI will open and operate properly (tested on Windows and MacOS).  Of course, Python is blocked until control is returned.  If you stop the event loop (without terminating everything else), control is returned to Python.  You can re-start the event loop and return control to FLTK.

This works so far.  You can have the application GUI in a 'blocking' mode -- either the GUI is responsive, or Python can work.

We are working to make the GUI available in a non-blocking mode.  To do this, we need to compile the SWIG wrapper with the -threads option -- thereby the program gets and releases the Python GIL (global interpreter lock) as appropriate.

Then, if we start the application GUI up in a Python thread, the GUI seems to work, and Python can continue.  This seems to work fine on Windows.

However, on MacOS, when the GUI is being initialized in a secondary thread, execution hangs on a call to:

Fl::screen_xywh( x, y, w, h );

If that call is commented out, we instead hang a few lines later on a call to:

Fl_Sys_Menu_Bar::add()

In the FLTK documentation, it says:

Key amongst these is that, for many of the target platforms on which FLTK is supported, only the main() thread of the process is permitted to handle system events, create or destroy windows and open or close windows. Further, only the main() thread of the process can safely write to the display.

I think I might be running into this problem.

How can I know if this is the problem I am experiencing?

If I am hitting this problem, what will it take to get FLTK to work in the thread created for it by Python?

Is there any way to make the new thread the 'main' thread?

What would happen if someone wanted to use some other GUI with a separate event loop in the main Python thread?

Rob

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/ca855804-ba22-45c4-859e-17a0ee7220dan%40googlegroups.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.