You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have written the following function in python that use python-libsass to preprocess sass on runtime in production, and in development, that watch for change using boussole:
importglobimportosfrompathlibimportPathimportsignalfromsubprocessimportDEVNULLfromsubprocessimportPopenfromsubprocessimportSTDOUTimportsassfrompcapiimportsettingsdefpreprocess_scss(watch: bool) ->None:
source=Path("src/pcapi/static/backofficev3/scss")
destination=Path("src/pcapi/static/backofficev3/css/compiled")
configuration=Path("src/pcapi/static/backofficev3/scss/boussole.yml")
pid_file_path=Path("src/pcapi/static/backofficev3/scss/boussole.pid")
Path(destination).mkdir(parents=True, exist_ok=True)
ifsettings.IS_RUNNING_TESTSisnotTrue:
ifwatch:
ifos.environ.get("WERKZEUG_RUN_MAIN") !="true":
has_never_compiled_css=len(glob.glob(f"{destination}/**/*.css", recursive=True)) ==0ifhas_never_compiled_css:
sass.compile(
dirname=(source, destination),
output_style="compressed",
source_map_contents=True,
source_map_embed=True,
source_map_root=destination,
)
# kill previous boussole process if python previously crashedtry:
ifos.path.isfile(pid_file_path):
withopen(pid_file_path, "r", encoding="utf8") aspid_file:
pid=int(pid_file.read())
pid_file.close()
os.kill(pid, signal.SIGTERM)
exceptException: # pylint: disable=broad-exceptpassproc=Popen( # pylint: disable=consider-using-with
["boussole", "watch", "--config", configuration, "--backend", "yaml"],
stdout=DEVNULL,
stderr=STDOUT,
)
# save new process pid in case of python crashwithopen(pid_file_path, "w", encoding="utf8") aspid_file:
pid_file.write(str(proc.pid))
pid_file.close()
print("💅 Scss compiler attached and watching, enjoy styling 💅", flush=True)
else:
sass.compile(
dirname=(source, destination),
output_style="compressed",
source_map_contents=True,
source_map_embed=True,
source_map_root=destination,
)
print("💅 Scss compiler has compiled css 💅", flush=True)
This work well for production, however, with boussole it watch for change, but I keep having my python process crashing with :
Traceback (most recent call last):
File "/usr/local/lib/python3.10/shutil.py", line 713, in rmtree
ImportError: sys.meta_path is None, Python is likely shutting down
I already took caution not to rerun the process when I have the flask hotreload on *.py edition by clearing the previous subprocess on restart. I checked and I only have one process running all the time.
It work fine when I do not run the boussole subprocess with python.
I have written the following function in
python
that usepython-libsass
to preprocesssass
on runtime inproduction
, and in development, that watch for change usingboussole
:This work well for production, however, with boussole it watch for change, but I keep having my python process crashing with :
I already took caution not to rerun the process when I have the flask hotreload on
*.py
edition by clearing the previous subprocess on restart. I checked and I only have one process running all the time.It work fine when I do not run the boussole subprocess with python.
This is my
boussole.yml
configuration:I use
boussole==2.1.0
andlibsass==0.22.0
.What can cause
rmtree
to fail then?The text was updated successfully, but these errors were encountered: