Skip to content

Commit

Permalink
use tempfile func (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
kemingy authored Oct 7, 2021
1 parent 3e30daa commit c813fd3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion mosec/args.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import argparse
import os
import tempfile


class ArgParser:
Expand All @@ -14,7 +16,7 @@ def parse(cls) -> argparse.Namespace:
"--path",
help="Unix Domain Socket address for internal Inter-Process Communication",
type=str,
default="/tmp/mosec",
default=os.path.join(tempfile.gettempdir(), "mosec"),
)

parser.add_argument(
Expand Down
3 changes: 1 addition & 2 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use clap::{crate_version, AppSettings, Clap};
#[derive(Clap, Debug)]
#[clap(version = crate_version!())]
#[clap(setting = AppSettings::ColoredHelp)]

pub(crate) struct Opts {
/// Unix domain socket directory path
#[clap(long, default_value = "/tmp/mosec")]
#[clap(long, default_value = "")]
pub(crate) path: String,

/// batch size for each stage
Expand Down
12 changes: 11 additions & 1 deletion src/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,24 @@ impl Coordinator {
let (sender, receiver) = bounded(opts.capacity);
let timeout = Duration::from_millis(opts.timeout);
let wait_time = Duration::from_millis(opts.wait);
let path = if opts.path.len() > 0 {
opts.path.to_string()
} else {
// default IPC path
std::env::temp_dir()
.join(env!("CARGO_PKG_NAME"))
.into_os_string()
.into_string()
.unwrap()
};
let task_manager = TaskManager::new(timeout, sender.clone());
TASK_MANAGER.set(task_manager).unwrap();
let metrics = Metrics::init_with_namespace(&opts.namespace, opts.timeout);
METRICS.set(metrics).unwrap();

Self {
capacity: opts.capacity,
path: opts.path.to_string(),
path: path,
batches: opts.batches.clone(),
wait_time,
timeout,
Expand Down
3 changes: 2 additions & 1 deletion tests/test_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import shutil
import socket
import struct
import tempfile
import time
from contextlib import ContextDecorator
from os.path import join
Expand All @@ -19,7 +20,7 @@
from .mock_logger import MockLogger
from .utils import imitate_controller_send

socket_prefix = "/tmp/test-mosec/"
socket_prefix = join(tempfile.gettempdir(), "test-mosec")
stage = STAGE_INGRESS + STAGE_EGRESS


Expand Down

0 comments on commit c813fd3

Please sign in to comment.