I converted a large notebook (a ton of code!) into a free-standing WolframScript. When I run the script:

  1. several warnings of the form FrontEndObject::notavail: A front end is not available; certain operations require a front end. appear on the screen (as usual, these warnings eventually get suppressed);
  2. the script will hang indefinitely if no X11 display is available (e.g. when it is run on a remote server via a text-only interface).

Of these two problems, the second one is the more serious one, but I suspect that the two are related, and that the first one may be the easier one to diagnose.

Hence, I'd like to find what exactly in my code is resulting in the FrontEndObject::notavail warnings. Since it's a lot of code (and, of course, I can't use the front end for debugging this), I'm looking for ideas to speed up the search.

FWIW, the code, even when run on the front end, sends no output to it. Its job is to read data from some input files, process the data, and write the result to other files.


If you want to find where a message was generated, you can set a message handler that will print the Stack or the relevant parts of the Stack. It does take some experimentation to distill the stack down to some human readable useful output though.

Before doing this, I would check if the code contains any of the usual things that require a front end:

  • Anything that renders or exports graphics, including Rasterize, Export to graphics formats (even PDF or EPS), etc.
  • Any notebook operations

On a headless server, use Xvfb to allow the front end to run and render graphics without a screen.

  • $\begingroup$ Thanks, that was extremely helpful. AFAICT, the use of Xvfb requires root privileges, which I don't have in the system where I need to run this. My only hope now is to eliminate all the operations that require a front end. I've brought these down to one. I'll post a separate question about it. Thanks again. $\endgroup$
    – kjo
    Dec 12 '16 at 15:23
  • 1
    $\begingroup$ @kjo It should be possible to run Xvfb without root, so don't give up on it ... but last time I used it it was several years ago. I don't remember the details. Recently I either used Export only while working interactively, in which case an ssh -X is sufficient to provide an X server (the X server will be running on your machine, not remotely), or more commonly: I just don't use Export. I compute the results and plot them on my laptop. But there are indeed very good reasons to run Export on the server (I was just lucky enough not to have to do that recently). $\endgroup$
    – Szabolcs
    Dec 12 '16 at 15:29
  • $\begingroup$ Hi, @Szabolcs. I tried your messageHandler. Though it stopped when there is error, but I still don't know at which line it stops, for example pasteboard.co/Hlwqwtr.png . How can I know exactly where goes wrong? $\endgroup$
    – matheorem
    May 17 '18 at 1:10

This is somewhat too long for a comment so I'll put it here:

You could try scraping your script for things that are likely to call the front end.

Assuming your script is in a .m here's a pair of functions for that.

   thing_] :=
  (StringContainsQ[ToString@Unevaluated@thing, $test]);

checkFor[script_, symbols__] :=
 With[{test = Alternatives @@ (ToString /@ {symbols})},
  $test = test;
   Quiet@Import[script, "HeldExpressions"],
   (head_?checkTest)[args___] :> Hold[head[args]],

Then try, say, checkFor[script,FrontEnd,FE,Notebook,Graph,Plot, etc.]

Obviously this isn't a full answer, but hopefully it's a start.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.