From 7ad5b56b9f07141ea81ea3fed072ef6da5d2d791 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 1 Mar 2017 17:26:55 +0100 Subject: [PATCH] When renaming the exported G-code (removing the .tmp suffix), some other application (thank you, Windows Explorer) may keep the file locked. Try to wait a bit and then rename the file again. by @bubnikv --- lib/Slic3r/Print.pm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 30805c3445..372a0c35c5 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -101,7 +101,16 @@ sub export_gcode { # close our gcode file close $fh; - rename Slic3r::encode_path($tempfile), Slic3r::encode_path($output_file) if $tempfile; + if ($tempfile) { + my $renamed = 0; + for my $i (1..5) { + last if $renamed = rename Slic3r::encode_path($tempfile), Slic3r::encode_path($output_file); + # Wait for 1/4 seconds and try to rename once again. + select(undef, undef, undef, 0.25); + } + Slic3r::debugf "Failed to remove the output G-code file from $tempfile to $output_file. Is $tempfile locked?\n" + if !$renamed; + } } # run post-processing scripts