This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #293 from dougbenjamin/next
fix file type check for python 3
- Loading branch information
Showing
4 changed files
with
19 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,13 @@ | |
# - Wen Guan, [email protected], 2017-2018 | ||
# - Paul Nilsson, [email protected], 2018-2019 | ||
|
||
import io | ||
import json | ||
import logging | ||
import os | ||
import re | ||
import subprocess | ||
import sys | ||
import time | ||
import threading | ||
import traceback | ||
|
@@ -29,6 +31,12 @@ | |
|
||
logger = logging.getLogger(__name__) | ||
|
||
try: | ||
file_type = file | ||
except NameError: | ||
file_type = io.IOBase | ||
|
||
|
||
""" | ||
Main process to handle event service. | ||
It makes use of two hooks get_event_ranges_hook and handle_out_message_hook to communicate with other processes when | ||
|
@@ -161,7 +169,7 @@ def init_payload_process(self): # noqa: C901 | |
executable = 'cd %s; %s' % (workdir, executable) | ||
|
||
if 'output_file' in self.__payload: | ||
if type(self.__payload['output_file']) in [file]: | ||
if isinstance(self.__payload['output_file'], file_type): | ||
output_file_fd = self.__payload['output_file'] | ||
else: | ||
if '/' in self.__payload['output_file']: | ||
|
@@ -174,7 +182,7 @@ def init_payload_process(self): # noqa: C901 | |
output_file_fd = open(output_file, 'w') | ||
|
||
if 'error_file' in self.__payload: | ||
if type(self.__payload['error_file']) in [file]: | ||
if isinstance(self.__payload['error_file'], file_type): | ||
error_file_fd = self.__payload['error_file'] | ||
else: | ||
if '/' in self.__payload['error_file']: | ||
|
@@ -376,6 +384,8 @@ def send_event_ranges_to_payload(self, event_ranges): | |
msg = None | ||
if "No more events" in event_ranges: | ||
msg = event_ranges | ||
if (sys.version_info > (3, 0)): # needed for Python 3 | ||
msg = msg.encode('utf-8') | ||
self.is_no_more_events = True | ||
self.__no_more_event_time = time.time() | ||
else: | ||
|
@@ -467,6 +477,8 @@ def handle_messages(self): | |
except queue.Empty: | ||
pass | ||
else: | ||
if (sys.version_info > (3, 0)): # needed for Python 3 | ||
message = message.decode('utf-8') | ||
logger.debug('received message from payload: %s' % message) | ||
if "Ready for events" in message: | ||
event_ranges = self.get_event_range_to_payload() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters