3

There is a module called _subprocess, as seen in that question.

I was able to import it, but I haven't found any documentation about what is it and how it is different from subprocess.

Anybody here know what this module does?

Community
  • 1
  • 1
iTayb
  • 12,373
  • 24
  • 81
  • 135

3 Answers3

4

_subprocess seems to be a Windows-specific C extension module that implements some of the functionality that's used by the subprocess module proper. If you look in the source for subprocess, _subprocess is only referred to inside of if mswindows blocks.

It's a detail of the implementation, and so you definitely shouldn't use it in any actual code (though of course some curiosity is never a bad thing).

Here's the source for `_subprocess'. The comment at the top says

* support routines for subprocess module
*
* Currently, this extension module is only required when using the
* subprocess module on Windows, but in the future, stubs for other
* platforms might be added here as well.
Danica
  • 28,423
  • 6
  • 90
  • 122
3

It's an implementation detail, present on Windows but not (e.g.) on Unix systems. You are not supposed to use it.

Gareth McCaughan
  • 19,888
  • 1
  • 41
  • 62
2

As with other names in Python starting with an underscore, such modules are usualy not meant to be used directly. Usually there is a module without the underscore that should be used instead, as is the case with subprocess.

This is often used to divide module implementation into parts coded in C and pure Python. The underscored module is written in C and a pure Python module is added "on top of it" to provide a high level API.

yak
  • 8,851
  • 2
  • 29
  • 23
  • In that way, the C implementation should be faster, isn't it? – iTayb Apr 26 '12 at 07:00
  • 3
    It gives you best of both worlds. The underlying C module is fast but implements only a thin wrapper around C functions. The Python module then exposes that with a pythonic API and adds things that aren't performance-critical or can be implemented easier in Python. You could use the underlying module directly but it will be harder to use, have limited functionality and the Python module will be just as fast (because it will use the C module to do the actual work). – yak Apr 26 '12 at 13:32