mailing-list for TeXmacs Users

Text archives Help


Re: [TeXmacs] Is SIGINT sent to plugins ?


Chronological Thread 
  • From: Nicola Mingotti <address@hidden>
  • To: Massimiliano Gubinelli <address@hidden>
  • Cc: texmacs-users <address@hidden>
  • Subject: Re: [TeXmacs] Is SIGINT sent to plugins ?
  • Date: Wed, 12 Dec 2018 10:01:07 -0800


Hi Max,


On 12/12/18 8:56 AM, Massimiliano Gubinelli wrote:
Hi again,

On 11. Dec 2018, at 20:11, Nicola Mingotti <address@hidden> wrote:

Hi again,

I am puzzled, I am trying to get the SIGINT from my plugin
but it seems to me TeXmacs is not sending that signal.


Seems there is a bug with the signals. I attach a patch and a test program
(which has to be installed as a plugin).

I will commit a patch in svn.

Best
Max


-----------------------------------------------------------------------
The patch
-8<---------------------------------------------------------------------
Index: src/Plugins/Qt/qt_pipe_link.cpp
===================================================================
--- src/Plugins/Qt/qt_pipe_link.cpp (revision 11316)
+++ src/Plugins/Qt/qt_pipe_link.cpp (working copy)
@@ -148,7 +148,11 @@
qt_error << "SIGINT not implemented on Windows\n";
#else
Q_PID pid = PipeLink.pid ();
- int ret = ::killpg (pid, SIGINT);
+
+ // REMARK: previously there were here below a call to ::killpg which does
not seems to work on MacOS
+ // I (mgubi) replaced it with ::kill which does the job. But I do not
undestand the difference.
+
+ int ret = ::kill (pid, SIGINT);
if (ret == -1) {
qt_error << "Interrupt not successful, pid: " << pid << " return code: " << errno
<< "\n";
}
-8<--------------------------------------------------------------------
The test program
-8<--------------------------------------------------------------------
#include <iostream>
#include <unistd.h>
#include <csignal>

using namespace std;

#define DATA_BEGIN ((char) 2)
#define DATA_END ((char) 5)
#define DATA_ESCAPE ((char) 27)

bool trig = true;
int cc = 0;

void signalHandler( int signum ) {
trig = false;
}

int
main () {
cout << DATA_BEGIN << "verbatim:";
cout << "STARTING\n";
cout << DATA_END;
cout.flush ();

// register signal SIGINT and signal handler
signal(SIGINT, signalHandler);

while (1) {
char buffer[100];
cin.getline (buffer, 100, '\n');
cout << DATA_BEGIN << "verbatim:";
cout << "Input: " << buffer << "\n";
cout.flush ();

while (trig) {
cout << "Going to sleep.... (" << cc ++ << ")\n";
cout.flush ();
sleep (1);
}
cout << DATA_END;
cout.flush ();
trig = true; cc = 0;
}
return 0;
}
-8<--------------------------------------------------------------------


I am using TeXmacs version 1.99.4 in FreeBSD.

Do you know of any plugin who is actually managing SIGINT correctly ?
I tried Python (not working, not implemented IFACSay), Scheme (no button),
Maxima (not working).

I test the SIGINT is not working in this way, for Python i can actually
check there is not signal receiver in the code, so, not a TeXmacs problem,
but the method I use in general is:

1] Run a sleep command, 10 seconds
2] Press the STOP button in TeXmacs
3] Run a simple arithmentic command e.g. 1+1

=== Pyjhon ===
import time
timp.sleep(10)
PRESS QUIT
1+1
HANGS till end of sleep
=============

==== Maxima ====
:lisp (sleep 10)
PRESS QUIT
1
HANGS till end of sleep
================

Maybe also Maxima plugin is not catching the SIGINT...
In my plugin managed to receive the signal but I don't see it coming when i
press the STOP button.

Do you know something about it ?

bye
Nicola




Thank you a lot Max !

This is really an important feature and it should be working.

I was trying to trace the call from STOP button pressure downwill, but i could not
solve it. In particular I was not able to unfold the thing down until arriving to the
file you point: qt_pipe_link.cpp .  I attach you my notes. I know almost nothing of Qt programming
probably i got lost for it.

But, ok, I will try to insert your patch manually and recompile the Freebsd port.

I will let you know ASAP.

Sorry for the late replay.

bye
Nicola








<TeXmacs|1.99.4>

<style|generic>

<\body>
  ====== Notes on plugin STOP button ====================

  Tracing the call top down: from the STOP button pressure downhill.

  \ 

  -] <with|color|red|program-menu.scm> : STOP icon calls
  <marked|(plugin-interrupt)>

  -] <marked|plugin-interrupt> is defined in <with|color|red|plugin-eval.scm>\ 

  \;

  (tm-define (<marked|plugin-interrupt>)<next-line><nbsp>(let* ((lan (get-env
  ``prog-language"))<next-line><nbsp><nbsp><nbsp><nbsp><nbsp><nbsp><nbsp><nbsp>(ses
  (get-env ``prog-session")))<next-line><nbsp><nbsp><nbsp>(if (==
  (connection-status lan ses) 3)<next-line><nbsp><nbsp><nbsp><nbsp><nbsp><nbsp><nbsp>(<marked|connection-interrupt>
  lan ses))<next-line><nbsp><nbsp><nbsp>(plugin-cancel lan ses
  #f)))<next-line>

  -]<space|1em><verbatim|(connection-interrupt \Pruby\Q \Pdefault\Q)> does
  not interrupt connection when Ruby has been sent to sleep. That is, Ruby
  keeps on sleeping. Let's see what it calls.

  -] In <with|color|red|build-glue-basic.scm> <marked|connection-interrupt>
  seems to call <marked|connection_interrupt><next-line>

  -] In file: <with|color|red|... System/Link/connection.cpp> , it seems the
  method \Pinterrupt\Q is called on \Pcon\Q (connection object)\ 

  void<next-line><marked|connection_interrupt> (string name, string session)
  {<next-line><nbsp>// cout \<less\>\<less\> ``Interrupt '' \<less\>\<less\>
  name \<less\>\<less\> ``, '' \<less\>\<less\> session \<less\>\<less\>
  ``\\n";<next-line><nbsp>connection con= connection (name * ``-'' *
  session);<next-line><nbsp>if (is_nil (con))
  return;<next-line><nbsp><marked|con-\<gtr\>interrupt
  ();><next-line><nbsp>con-\<gtr\>listen ();<next-line>}<next-line>

  void<next-line>connection_rep::interrupt () {<next-line><nbsp>if
  (ln-\<gtr\>alive) {<next-line><nbsp><marked|ln-\<gtr\>interrupt
  ();><next-line><nbsp><nbsp><nbsp>if (status ==
  WAITING_FOR_OUTPUT)<next-line><nbsp><nbsp><nbsp><nbsp><nbsp>status=
  CONNECTION_DYING;<next-line><nbsp>}<next-line>}<next-line><next-line><marked|RESOURCE(connection);><next-line>struct
  connection_rep: rep\<less\>connection\<gtr\> {<next-line><nbsp>string
  <nbsp>name; <nbsp><nbsp><nbsp><nbsp><nbsp><nbsp><nbsp><nbsp><nbsp>// name
  of the pipe type<next-line><nbsp>string <nbsp>session;
  <nbsp><nbsp><nbsp><nbsp><nbsp><nbsp>// name of the
  session<next-line><nbsp><marked|tm_link ln;
  <nbsp><nbsp>><nbsp><nbsp><nbsp><nbsp><nbsp><nbsp><nbsp><nbsp><nbsp>// the
  underlying link<next-line><nbsp>int <nbsp><nbsp><nbsp><nbsp>status;
  <nbsp><nbsp><nbsp><nbsp><nbsp><nbsp><nbsp>// status of the
  connection<next-line><nbsp>int <nbsp><nbsp><nbsp><nbsp>prev_status;
  <nbsp><nbsp>// last notified status<next-line><nbsp>bool
  <nbsp><nbsp><nbsp>forced_eval; <nbsp><nbsp>// forced input evaluation
  without call backs<next-line><nbsp>texmacs_input tm_in; <nbsp><nbsp>//
  texmacs input handler for data from child<next-line><nbsp>texmacs_input
  tm_err; <nbsp>// texmacs input handler for errors from
  child<next-line><next-line>public:<next-line><nbsp>connection_rep (string
  name, string session, tm_link ln);<next-line><nbsp>string start (bool
  again);<next-line><nbsp>void <nbsp><nbsp>write (string
  s);<next-line><nbsp>void <nbsp><nbsp>read (int
  channel);<next-line><nbsp>void <nbsp><nbsp>stop ();<next-line><nbsp>void
  <nbsp><nbsp>interrupt ();<next-line><nbsp>void <nbsp><nbsp>listen
  ();<next-line>};<next-line>RESOURCE_CODE(connection);<next-line><next-line>-]
  The last file includes <with|color|red|connect.hpp> which includes
  <with|color|red|tm_link.hpp>

  -] In <with|color|red|tm_link.hpp> interrupt method is declared but it is
  not defined in in <with|color|red|tm_link.cpp>

  \;

  =======\<gtr\> I can't connect to qt_pipe_link.cpp\ 

  -] In file <with|color|red|qt_pipe_link.cpp><next-line>

  void<next-line>qt_pipe_link_rep::interrupt () {<next-line><nbsp>if (!alive)
  return;<next-line>#if defined(__MINGW__) \|\|
  defined(__MINGW32__)<next-line><nbsp>// Not
  implemented<next-line>#else<next-line><nbsp><marked|::killpg(PipeLink.pid
  (), SIGINT);><next-line>#endif<next-line>}<next-line><next-line>
</body>

<\initial>
  <\collection>
    <associate|font-base-size|9>
    <associate|font-family|tt>
  </collection>
</initial>



Archive powered by MHonArc 2.6.19.

Top of page