I'm trying to Run two processes simultaneously;

datastream[filepath_, pythoncode_] := Module[{pysession, codename},
   If[StringTake[filepath, -1] == "/",
    codename = StringJoin[filepath, pythoncode],
    codename = StringJoin[filepath, "/", pythoncode]];
   pysession = StartExternalSession["Python"];
   ExternalEvaluate[pysession, File[codename]];
dataplot[filepath_, prodlabel1_] := 
  Module[{prevln1, bgntm, date, prodate, imprtdata1, dtln1, plt, 
   prevln1 = 0;
     AbsoluteTime[] < 
       StringJoin[StringDrop[DateString[AbsoluteTime[Today]], -8], 
     bgntm = AbsoluteTime[];
     date = Today;
     prodate = 
      StringDrop[DateString[AbsoluteTime[date], "ISODate"], 2];
     imprtdata1 = 
      Import[StringJoin[filepath, "DATAFILE_", prodlabel1, "_", 
        prodate, ".csv"], "CSV"];
     dtln1 = Length[imprtdata1];
     If[dtln1 > prevln1 && dtln1 > 1,
      plt = {DateListPlot[imprtdata1[[All, {1, 4}]], Joined -> True, 
         PlotRange -> All, ImageSize -> 1200, AspectRatio -> 1/9, 
         GridLines -> Automatic, Frame -> True, 
         FrameTicks -> {{Automatic, All}, {Automatic, None}}, 
         PlotLabel -> prodlabel1]};
      prevln1 = dtln1;
     cmptm = AbsoluteTime[] - bgntm;
     Pause[20 - cmptm];
    plt, plt]

Individual functions work fine, however, when I'm trying to run them simultaneously using the following code

task[i_] := 
 If[i == 1, datastream["/home/csk7/Documents/callPy", "main.py"], 
  If[i == 2, 
Table[ParallelSubmit[{i}, task[i]], {i, 1, 2}]

Getting the following error;

FrontEndObject::notavail :  A front end is not available; certain operations require a front end.
Ticker WS Active...

The 72, 109 which are the length of the data file, and Connected, Ticker WS Active... indicate both codes are running except that the DateListPlot under Monitor is not working.

ANY SUGGESTIONS, how to fix it, so that it keeps on plotting the data as the data stream is received?

  • $\begingroup$ Can you lookup UsingFrontEnd in the documentation and check whether that solves your problem? $\endgroup$ Dec 4, 2022 at 18:40
  • $\begingroup$ @AlbertRetey: I tried UsingFrontEnd in the dataplot function inside task, before DateListPlot, before plt, before Monitor, however didn't work. $\endgroup$
    – csk 7
    Dec 4, 2022 at 21:21
  • $\begingroup$ Do you still get the same message with the UsingFrontEnd ? If it doesn't work with it, you would need to find which of the commands is not working. I suggest you try to minimize the problem to the minimal failing code, that will make it more likely someone can help... $\endgroup$ Dec 5, 2022 at 22:39


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.