Skip to content

Commit 01e2ce9

Browse files
authored
Merge pull request #103 from anomal/bugFix/ctrlC
Properly handle SIGINT by terminating process gracefully
2 parents bcea230 + 6b72f9f commit 01e2ce9

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

big_sleep/big_sleep.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
terminate = False
3131

3232
def signal_handling(signum,frame):
33+
print('detecting keyboard interrupt, gracefully exiting')
3334
global terminate
3435
terminate = True
3536

@@ -494,13 +495,11 @@ def forward(self):
494495
self.open_folder = False
495496

496497
image_pbar = tqdm(total=self.total_image_updates, desc='image update', position=2, leave=True)
497-
for epoch in trange(self.epochs, desc = ' epochs', position=0, leave=True):
498+
epoch_pbar = trange(self.epochs, desc = ' epochs', position=0, leave=True)
499+
for epoch in (ep for ep in epoch_pbar if not terminate):
498500
pbar = trange(self.iterations, desc=' iteration', position=1, leave=True)
499501
image_pbar.update(0)
500-
for i in pbar:
502+
for i in (it for it in pbar if not terminate):
501503
out, loss = self.train_step(epoch, i, image_pbar)
502504
pbar.set_description(f'loss: {loss.item():04.2f}')
503505

504-
if terminate:
505-
print('detecting keyboard interrupt, gracefully exiting')
506-
return

0 commit comments

Comments
 (0)