def _execute(self, wait=False):
        code = """if 1: # For indentation
            import os, sys, time
            from encore.concurrent.futures.enhanced_thread_pool_executor \
                    import EnhancedThreadPoolExecutor

            def job():
                time.sleep(1)
                sys.stdout.write('FINISHED')
                sys.stdout.flush()

            executor = EnhancedThreadPoolExecutor(max_workers=4,
                            wait_at_exit=int(os.environ['SHOULD_WAIT']))
            executor.submit(job)
        """
        return assert_python_ok('-c', code, SHOULD_WAIT=str(int(wait)))
    def _execute(self, wait=False):
        code = """if 1: # For indentation
            import os, sys, time
            from encore.concurrent.futures.enhanced_thread_pool_executor \
                    import EnhancedThreadPoolExecutor

            def job():
                time.sleep(1)
                sys.stdout.write('FINISHED')
                sys.stdout.flush()

            executor = EnhancedThreadPoolExecutor(max_workers=4,
                            wait_at_exit=int(os.environ['SHOULD_WAIT']))
            executor.submit(job)
        """
        return assert_python_ok('-c', code, SHOULD_WAIT=str(int(wait)))
 def test_interpreter_shutdown(self):
     # Test the atexit hook for shutdown of worker threads and processes
     rc, out, err = assert_python_ok('-c', """if 1:
         from encore.concurrent.futures.enhanced_thread_pool_executor import EnhancedThreadPoolExecutor
         from time import sleep
         import sys
         def sleep_and_print(t, msg):
             sleep(t)
             print msg
             sys.stdout.flush()
         t = {executor_type}(5)
         t.submit(sleep_and_print, 1.0, "apple")
         """.format(executor_type=self.executor_type.__name__))
     # Errors in atexit hooks don't change the process exit code, check
     # stderr manually.
     self.assertFalse(err)
     self.assertEqual(out.strip(), b"apple")
 def test_interpreter_shutdown(self):
     # Test the atexit hook for shutdown of worker threads and processes
     rc, out, err = assert_python_ok('-c', """if 1:
         from encore.concurrent.futures.enhanced_thread_pool_executor import EnhancedThreadPoolExecutor
         from time import sleep
         import sys
         def sleep_and_print(t, msg):
             sleep(t)
             print msg
             sys.stdout.flush()
         t = {executor_type}(5)
         t.submit(sleep_and_print, 1.0, "apple")
         """.format(executor_type=self.executor_type.__name__))
     # Errors in atexit hooks don't change the process exit code, check
     # stderr manually.
     self.assertFalse(err)
     self.assertEqual(out.strip(), b"apple")