question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow to read from stdin

See original GitHub issue

So it is possible to use functions like scanf.

Thanks to @ryukinix for letting me know about this enhancement.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:4
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
spoorcccommented, Apr 13, 2017

I’m trying to implement this, but I’m a little stuck: My idea is to override all fgets calls with my_fgets using a macro. This my_fgets in master.c notifies its parent (subprocess.Popen in kernel.py) somehow to send an input_request through stdin_socket. When input_reply is received from the frontend the data is piped to the stdin of subprocess.

I managed to request and receive input from the frontend as such, which works just fine:

 def _raw_input(self, prompt, ident, parent):
          # Flush output before making the request.
          sys.stderr.flush()
          sys.stdout.flush()

          # Send the input request.
          content = dict(prompt=prompt)
          msg = self.session.send(self.stdin_socket, u'input_request', content, parent, ident=ident)

          # Await a response.
          ident,reply = self.session.recv(self.stdin_socket, 0)
          try:
              value = reply['content']['value']
          except:
              self.log.error("Got bad raw_input reply: %s"%Message(parent))
              value = ''
          return value

    def execute_request(self, stream, ident, parent):
        ''' Wrap execture_request function to force input call '''
        value = self._raw_input('Some info:', ident, parent)
        self.log.warn('Value: {}'.format(value))
        super(CKernel, self).execute_request(stream, ident, parent)

Questions

I cannot find or decide on a mechanism to notify from master.c to Python subprocess instance that input is requested:

  • Is there anybody with an opinion or a better suggestion than:
    • Using zmq sockets directly from master.c?
    • Introducing new messaging system between master.c and kernel.py?
    • Piping some predefined message through stderr/stdout?
  • I looked into raising signals SIGTTIN and SIGTTOU (good blog), but they appear to be used from parent-to-child and I want from child to parent.
1reaction
sdd3commented, Apr 29, 2016

Ah, ok. I misunderstood the first post in this thread. Thanks for clearing that up. Any idea when an input function might be incorporated?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Allow program to read from stdin or arguments in Swift
Allow program to read from stdin or arguments in Swift · Accepts either a single argument or piped data from standard input, and...
Read more >
allow to read input from stdin · Issue #13 - GitHub
As per title. Weirdly enough, currently beancount2ledger accepts "-" as an argument, without failing, but it does nothing: $ beancount2ledger - ...
Read more >
How does `less` take data from stdin while still be able to read ...
Yes, there is one input stream, and one tty. less reads data from stdin, and commands from the tty. – William Pursell. Jun...
Read more >
Stdin in std::io - Rust
This handle implements the Read trait, but beware that concurrent reads of Stdin must be executed with care. Created by the io::stdin method....
Read more >
How to Read from stdin in Python - DigitalOcean
Python sys module stdin is used by the interpreter for standard input. Internally, it calls the input() function. The input string is appended ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found