Skip to content

Instantly share code, notes, and snippets.

@nikcleju
Created March 8, 2022 17:33
Show Gist options
  • Save nikcleju/15875bcfe366ca17be6518c3e8ed593f to your computer and use it in GitHub Desktop.
Save nikcleju/15875bcfe366ca17be6518c3e8ed593f to your computer and use it in GitHub Desktop.
Xeus-cling keep alive in Mybinder
#include <iostream>
#include <thread>
#include <chrono>
#include "xcpp/xdisplay.hpp"
void threadFunc()
{
using namespace std::chrono_literals;
int repeat = 30;
for (int i=0; i < repeat; i++)
{
std::cout << "(Keep alive "<< i+1 << "/" << repeat << ")" << std::endl << std::flush;
// Sleep this thread for 300 Seconds
std::this_thread::sleep_for(290s); //300000ms = 300s = 5 min
//xcpp::clear_output(true); // prevents flickering
}
std::cout << "(Keep alive finished)";
}
//threadFunc()
std::thread th(&threadFunc);
th.detach();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment