Short answer: "the masculine gender wins out"
A composite subject will have a masculine gender as long as at least one of its parts is masculine. For instance, you would say or write
Tous les professeurs ont été invités à la kermesse de fin d’année. Tous sont venus.
even if there is one male teacher and a hundred female teachers, or
Les garçons et les filles sont allés jouer. Ils se sont bien amusés.
even if there are two boys and a thousand girls.
The rule applies with respect to the grammatical gender of the noun, not necessarily the gender of the person; for instance,
Les recrues / les sentinelles ont été surprises par l’assaut ennemi sur la base militaire
Les girafes ont été surprises par les lions
because une recrue (a recruit) or une sentinelle (a sentinel) are always feminine words even though the person might be a man, and une girafe (a giraffe) is always a feminine word no matter the gender of the individual Giraffa camelopardalis. (The names for the vast majority of non-pet animals exist in a single gender.)
Longer answer, and considerations of "political correctness"
As of 2024, this rule of primauté du masculin ("masculine gender predominance") is what you will find in the vast majority of grammar books, and is applied by the vast majority of native French speakers (at least in metropolitan French). As a consequence, if you break it, it will be assumed you are making a mistake, or failing that, that you are trying to joke about the one male person or insult them, depending on context.
This rule of masculine gender predominance was solidified into French around the eighteenth century. Before that, there was some variation about how to inflect verbs with multiple subjects of varying gender. The solution found was to decide that the masculine gender, being more "noble", wins out; see this Wikipedia article with examples and sourcing. (One modern defense of the rule is that the masculine gender is "neutral", i.e. corresponds to the non-inflected form, and therefore it is not really the masculine gender but rather the neutral gender that "wins out". I find this rather disingenuous given the historical evidence, but I digress.)
If you want to avoid applying this rule, you have a few options. I will try my best to present them without passing judgement, but I must make clear that the "best" option depends both on your sense of aesthetics and your willingness to go into a fight with someone arguing about your "mistakes", and my presentation might be affected by my own preferences.
Language épicène (gender-neutral language)
This rather large category aims to break the "masculine by default" assumption by either removing gender from the language used when irrelevant, or making sure that both genders are represented.
Here, in our example, one could use
Tous les professeurs et toutes les professeures sont invités à la kermesse de fin d’année.
or
Tou.te.s les professeur.e.s sont invité.e.s à la kermesse de fin d’année.
I would recommend the former formulation, which everybody agrees is proper French. (If someone asks why you did not employ the shorter form "Tous les professeurs sont invités...", they are looking for a fight.) It can also be employed orally with little inconvenience (you might want to pronounce the usually-silent e in the last syllable of "professeures", given that otherwise it pronounces identically to the masculine form; you would not have this problem with, say, "tous les infirmiers et toutes les infirmières").
The latter is fraught with more danger; some traditionalists consider it to not be proper French, and a large fraction of the population will see it as weird and non-standard.
From personal experience, a version with parentheses was in regular use around 2000-2015:
Tou(te)s les professeur(e)s...
but it has largely fallen out of fashion. I would speculate that since then, more people have become aware of gender issues around language and chosen a "camp"; the version with parentheses is rejected both by traditionalists (as a deviation from the good ol' ways) and by feminists (it puts the feminine gender in parentheses, i.e. in a non-equal, subordinate position).
Different inflection rules
L’accord de majorité (majority inflection) is a rule whereby a composite subject made of discrete gendered parts takes the gender of its majority. In our case, we would have
Toutes les professeures sont invitées à la kermesse de fin d’année.
as long as there are more female teachers than male teachers. However, this is hard to apply in many cases (if the parts of the subject are uncountable, or the numerical majority is unknown), and it has very little support even in feminist-adjacent circles.
L’accord de proximité (proximity inflection) has more support (in those circles, not in the general population). It holds that gender inflection should be made with the closest part of a composite subject. For instance:
Alexandre, Bertrand et Charline sont attendues à la fête
but
Alice, Brigitte et Charles sont attendus à la fête
(Alexandre, Bertrand and Charles are masculine names; Alice, Brigitte and Charline are feminine names.)
This can be applied to our previous example:
Tous les professeurs et toutes les professeures sont invitées à la kermesse de fin d’année.
...but it is a bit contrived, as the sentence already makes sure to mention the existence of female teachers. I would do this only for consistency, if you are using the proximity inflection in other sentences.
The proximity inflection has some historical support (it was the rule used by many authors before the aforementioned 18th century standardization push), but neither it nor the majority inflection are common. Using them is making a statement; the vast majority of French speakers will consider it a mistake, and some fraction of them will call you out on it. Do not use them if you are not ready to defend your choice.