fix memory limit

This commit is contained in:
Dominic 2023-11-02 21:33:21 +01:00
parent f4fe73bf5f
commit ca3ab6a788
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
2 changed files with 11 additions and 6 deletions

View file

@ -19,16 +19,22 @@ use std::{
collections::BTreeSet, collections::BTreeSet,
fmt::Display, fmt::Display,
fs, fs,
io::{self, BufRead as _, Write} io::{self, BufRead as _, Write},
sync::RwLock
}; };
static MEM_LIMIT: RwLock<String> = RwLock::new(String::new());
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
struct Args { struct Args {
#[clap(short = 'C', long, default_value = ".")] #[clap(short = 'C', long, default_value = ".")]
directory: PathBuf, directory: PathBuf,
#[clap(short = 'c', long, default_value = "23ws-malo")] #[clap(short = 'c', long, default_value = "23ws-malo")]
course: String course: String,
#[clap(short, long, default_value = "2G")]
mem_limit: String
} }
#[allow(non_camel_case_types, clippy::upper_case_acronyms)] #[allow(non_camel_case_types, clippy::upper_case_acronyms)]
@ -146,6 +152,7 @@ fn ask_time(question: impl Display) -> Time {
fn main() { fn main() {
let args = Args::parse(); let args = Args::parse();
*(MEM_LIMIT.write().unwrap()) = args.mem_limit;
// process arguments // process arguments
let directory = args.directory.canonicalize_utf8().unwrap(); let directory = args.directory.canonicalize_utf8().unwrap();

View file

@ -8,7 +8,7 @@ use crate::{
iotro::{intro, outro}, iotro::{intro, outro},
render::ffmpeg::{Ffmpeg, FfmpegInput}, render::ffmpeg::{Ffmpeg, FfmpegInput},
time::{format_date, Time}, time::{format_date, Time},
Project, ProjectSourceMetadata, Resolution Project, ProjectSourceMetadata, Resolution, MEM_LIMIT
}; };
use anyhow::{bail, Context}; use anyhow::{bail, Context};
use camino::{Utf8Path as Path, Utf8PathBuf as PathBuf}; use camino::{Utf8Path as Path, Utf8PathBuf as PathBuf};
@ -21,8 +21,6 @@ use std::{
process::{Command, Stdio} process::{Command, Stdio}
}; };
const MEMORY_LIMIT: &str = "2G";
const INTRO_LEN: Time = Time { const INTRO_LEN: Time = Time {
seconds: 3, seconds: 3,
micros: 0 micros: 0
@ -48,7 +46,7 @@ fn cmd() -> Command {
.arg("-q") .arg("-q")
.arg("--expand-environment=no") .arg("--expand-environment=no")
.arg("-p") .arg("-p")
.arg(format!("MemoryMax={MEMORY_LIMIT}")) .arg(format!("MemoryMax={}", MEM_LIMIT.read().unwrap()))
.arg("--user"); .arg("--user");
// we use busybox ash for having a shell that outputs commands with -x // we use busybox ash for having a shell that outputs commands with -x
cmd.arg("busybox") cmd.arg("busybox")