Repository: Qiskit/qiskit

Issue:
Jobs timeouts are wrongly managed.
<!--- Provide a general summary of the issue in the Title above -->
Timeouts are not working as expected.

## Expected Behavior
<!--- If you're describing a bug, tell us what should happen -->
<!--- If you're suggesting a change/improvement, tell us how it should work -->
When you set a timeout in `QuantumProgram.execute(timeout=<value>)` or  `.run(timeout=<value>)` we want this value to be the actual timeout (in secs).

## Current Behavior
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
Values passed are not being properly set, so the default 120 secs timeout is always being used.

## Steps to Reproduce (for bugs)
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
<!--- reproduce this bug. Include code to reproduce, if relevant -->
1. Call  `QuantumProgram.execute(timeout=0.01)` surrounded by `try: ... except QSIKitError:`
2. The method call should timeout and entering the `except` block, but it's not.

## Your Environment
<!--- Include as many relevant details about the environment you experienced the bug in -->
* Version used: 0.4.x (0.3 is not affected)
* Environment name and version (e.g. Python 3.6.1): 3.5 & 3.6
* Operating System and version: Linux, Mac and Windows.


Discussion:

Resolving patch:
diff --git a/qiskit/_quantumprogram.py b/qiskit/_quantumprogram.py
--- a/qiskit/_quantumprogram.py
+++ b/qiskit/_quantumprogram.py
@@ -1124,7 +1124,9 @@ def _run_internal(self, qobj_list, wait=5, timeout=60, callback=None,
 
         q_job_list = []
         for qobj in qobj_list:
-            q_job = QuantumJob(qobj, preformatted=True)
+            q_job = QuantumJob(qobj, preformatted=True, resources={
+                'max_credits':qobj['config']['max_credits'], 'wait':wait,
+                'timeout':timeout})
             q_job_list.append(q_job)
 
         job_processor = JobProcessor(q_job_list, max_workers=5,


Test patch:
diff --git a/test/python/test_quantumprogram.py b/test/python/test_quantumprogram.py
--- a/test/python/test_quantumprogram.py
+++ b/test/python/test_quantumprogram.py
@@ -1639,6 +1639,32 @@ def test_reconfig(self):
         self.assertEqual(qobj['circuits'][0]['config']['0'], 2)
         self.assertEqual(qobj['circuits'][0]['config']['1'], 1)
 
+    def test_timeout(self):
+        """Test run.
+
+        If all correct should the data.
+        """
+        QP_program = QuantumProgram(specs=self.QPS_SPECS)
+        qr = QP_program.get_quantum_register("qname")
+        cr = QP_program.get_classical_register("cname")
+        qc2 = QP_program.create_circuit("qc2", [qr], [cr])
+        qc2.h(qr[0])
+        qc2.cx(qr[0], qr[1])
+        qc2.cx(qr[0], qr[2])
+        qc2.measure(qr, cr)
+        circuits = ['qc2']
+        shots = 1024  # the number of shots in the experiment.
+        backend = 'local_qasm_simulator'
+        qobj = QP_program.compile(circuits, backend=backend, shots=shots,
+                                seed=88)
+        try:
+            out = QP_program.run(qobj, timeout=0.01)
+            self.assertTrue(False, "Should timeout! but it didn't!")
+        except QISKitError as ex:
+            self.assertEqual(ex.message,
+                'Error waiting for Job results: Timeout after 0.01 seconds.')
+
+
 
 if __name__ == '__main__':
     unittest.main(verbosity=2)