@imports(['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>','<STR_LIT>'])<EOL>def dump_item(inbox, type='<STR_LIT:file>', prefix=None, suffix=None, dir=None,timeout=<NUM_LIT>, buffer=None):
<EOL>names = tempfile._get_candidate_names()<EOL>names.rng.seed() <EOL>if type in ('<STR_LIT:file>', '<STR_LIT>'):<EOL><INDENT>prefix = prefix or '<STR_LIT>' % type<EOL>suffix = suffix or '<STR_LIT>'<EOL>dir = dir or tempfile.gettempdir()<EOL>while True:<EOL><INDENT>file = prefix + next(names) + suffix<EOL>if type in ('<STR_LIT:file>', '<STR_LIT>'):<EOL><INDENT>file = os.path.join(dir, file)<EOL>try:<EOL><INDENT>if type == '<STR_LIT:file>':<EOL><INDENT>fd = os.open(file, tempfile._bin_openflags, <NUM_LIT>)<EOL>tempfile._set_cloexec(fd) <EOL><DEDENT>elif type == '<STR_LIT>':<EOL><INDENT>os.mkfifo(file)<EOL><DEDENT>file = os.path.abspath(file)<EOL>break<EOL><DEDENT>except OSError as excp:<EOL><INDENT>try:<EOL><INDENT>os.close(fd)<EOL><DEDENT>except OSError as excp_:<EOL><INDENT>if excp_.errno == errno.EBADF:<EOL><INDENT>pass<EOL><DEDENT>raise excp_<EOL><DEDENT>if excp.errno == errno.EEXIST:<EOL><INDENT>continue<EOL><DEDENT>raise excp<EOL><DEDENT><DEDENT><DEDENT><DEDENT>elif type in ('<STR_LIT>',):<EOL><INDENT>sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<EOL>try:<EOL><INDENT>host = socket.gethostbyaddr(socket.gethostname())[<NUM_LIT:0>] <EOL><DEDENT>except socket.gaierror:<EOL><INDENT>host = urllib.request.urlopen(PAPY_DEFAULTS['<STR_LIT>']).read()<EOL><DEDENT>sock.bind(('<STR_LIT>', <NUM_LIT:0>))           <EOL>port = sock.getsockname()[<NUM_LIT:1>] <EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % type)<EOL><DEDENT>if type == '<STR_LIT:file>':<EOL><INDENT>handle = open(file, '<STR_LIT:wb>')<EOL>os.close(fd) <EOL>handle.write(inbox[<NUM_LIT:0>])<EOL>handle.close() <EOL>file = (type, file, <NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>if type == '<STR_LIT>':<EOL><INDENT>pid = os.fork()<EOL>if not pid:<EOL><INDENT>signal.alarm(timeout)<EOL>fd = os.open(file, os.O_EXCL & os.O_CREAT | os.O_WRONLY)<EOL>signal.alarm(<NUM_LIT:0>)<EOL>os.write(fd, inbox[<NUM_LIT:0>])<EOL>os.close(fd)<EOL>os._exit(<NUM_LIT:0>)<EOL><DEDENT>file = (type, file, pid)<EOL><DEDENT>elif type == '<STR_LIT>':<EOL><INDENT>sock.listen(<NUM_LIT:1>)<EOL>pid = os.fork()<EOL>if not pid:<EOL><INDENT>signal.alarm(timeout)<EOL>rsock, (rhost, rport) = sock.accept() <EOL>signal.alarm(<NUM_LIT:0>)<EOL>rsock.sendall(inbox[<NUM_LIT:0>])               <EOL>rsock.close()<EOL>sock.close()<EOL>os._exit(<NUM_LIT:0>)<EOL><DEDENT>sock.close()<EOL>file = (type, host, port)<EOL><DEDENT>tid = threading._get_ident()<EOL>try:<EOL><INDENT>pids = PAPY_RUNTIME[tid]<EOL><DEDENT>except KeyError:<EOL><INDENT>PAPY_RUNTIME[tid] = []<EOL>pids = PAPY_RUNTIME[tid]<EOL><DEDENT>add_pid = pids.append   <EOL>del_pid = pids.remove<EOL>add_pid(pid)<EOL>for pid in pids:<EOL><INDENT>try:<EOL><INDENT>killed, status = os.waitpid(pid, os.WNOHANG)<EOL>if killed:<EOL><INDENT>del_pid(pid)<EOL><DEDENT><DEDENT>except OSError as excp:<EOL><INDENT>if excp.errno == os.errno.ECHILD:<EOL><INDENT>continue<EOL><DEDENT>raise<EOL><DEDENT><DEDENT><DEDENT>return file<EOL>
Writes the first element of the inbox as a file of a specified type. The 
type can be 'file', 'fifo' or 'socket' corresponding to typical  files, 
named pipes (FIFOs). FIFOs and TCP sockets and are volatile i.e. exists only
as long as the Python process, which created them. FIFOs are local i.e.
allow to communicate processes only on the same computer.

This function returns a semi-random name of the file written. By default 
creates files and fifos in the default temporary directory. To use named 
pipes the operating system has to support both forks and fifos (not 
Windows). Sockets should work on all operating systems.

This function is useful to efficently communicate parallel ``Pipers`` 
without the overhead of using queues.

Arguments:

  - type('file', 'fifo', 'socket') [default: 'file'] Type of the created 
    file-like object.
  - prefix(``str``) [default: ``"tmp_papy_%type%"``] Prefix of the file to 
    be created. Should probably identify the ``Worker`` and ``Piper`` type. 
  - suffix(``str``) [default: ``''``] Suffix of the file to be created. 
    Should probably identify the format of the serialization protocol e.g. 
    ``"pickle"`` or deserialized data e.g. ``"nubox"``.
  - dir(``str``) [default: ``tempfile.gettempdir()``] Directory to safe the
    file to. (can be changed only for types ``"file"`` and ``"fifo"``)
  - timeout(``int``) [default: ``320``] Number of seconds to keep the 
    process at the write-end of the ``"socket"`` or ``"pipe"`` alive.