running FreeCAD in --console and --single-instance

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
sdementen
Posts: 7
Joined: Wed Jun 09, 2021 4:12 am

running FreeCAD in --console and --single-instance

Post by sdementen »

I would like to be able to run a script using FreeCAD as a library but that connects to the single existing instance.

When I run the script with

Code: Select all

FreeCAD --console my_script.py
I see the FreeCAD UI being open and the script running properly.
However, if I start first

Code: Select all

FreeCAD --single-instance
and afterwards

Code: Select all

FreeCAD --single-instance --console my_script.py
, it still opens a new FreeCAD instance of the UI.
Are the options --single-instance and --console not working together ?
chrisb
Veteran
Posts: 54293
Joined: Tue Mar 17, 2015 9:14 am

Re: running FreeCAD in --console and --single-instance

Post by chrisb »

sdementen wrote: Thu Jun 10, 2021 11:27 am Are the options --single-instance and --console not working together ?
I guess not. FreeCAD doesn't provide a server with multiple connections.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
sdementen
Posts: 7
Joined: Wed Jun 09, 2021 4:12 am

Re: running FreeCAD in --console and --single-instance

Post by sdementen »

That is understandable.

On a related point, if a FreeCAD instance is already running, when I run

Code: Select all

FreeCAD --single-instance --console my_script.py
, the script is not launched on the existing instance. Is this also not supported?
chrisb
Veteran
Posts: 54293
Joined: Tue Mar 17, 2015 9:14 am

Re: running FreeCAD in --console and --single-instance

Post by chrisb »

sdementen wrote: Thu Jun 10, 2021 6:04 pm the script is not launched on the existing instance. Is this also not supported?
If it is not launched, I guess it is not supported.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: running FreeCAD in --console and --single-instance

Post by wmayer »

Are the options --single-instance and --console not working together ?
No, they don't.

When you run the GUI version of FreeCAD with --single-instance then a server on a local socket will be started. If you start a second FreeCAD instance with --single-instance it tries to connect to the local socket server and if that succeeded it will forward its program parameters to the first instance and terminates itself.

In order to make this working a running event loop is required. However, the console version of FreeCAD doesn't have an event loop running and thus the single-instance mode isn't supported there.
the script is not launched on the existing instance. Is this also not supported?
If the second FreeCAD instance cannot connect to a running server it won't terminate itself and thus it won't forward its program parameters to this other instance. Again, because in console mode an event loop is never started it's not possible to connect to the first FreeCAD instance.
Post Reply