Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions coroutine/subprocess_target.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import pickle


def coroutine(func):
def start(*args, **kwargs):
rc = func(*args, **kwargs)
rc.next()
return rc

return start


# bridge two coroutine over a file/pipe

@coroutine
Expand All @@ -30,5 +33,9 @@ def fecvfrom(f, target):
except EOFError:
target.close()


def main():
pass

if __name__ == '__main__':
main()
22 changes: 14 additions & 8 deletions coroutine/thread_target.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from queue import Queue


def coroutine(func):
def start(*args, **kwargs):
rc = func(*args, **kwargs)
rc.next()
return rc

return start


@coroutine
def threaded(target):
messages = Queue() # message queue
messages = Queue() # message queue

def run_target():
while True:
item = messages.get() # A thread loop forever.pulling items out of
# the message queue and sending to the
# target
item = messages.get() # A thread loop forever.pulling items out of
# the message queue and sending to the
# target

if item is GeneratorExit: # handle close so that thread shuts down correctly
if item is GeneratorExit: # handle close so that thread shuts down correctly
target.close()
return
else:
Expand All @@ -29,12 +31,16 @@ def run_target():

try:
while True:
item = yield # receive items and pass them into the
# thread (via the queue)
item = yield # receive items and pass them into the
# thread (via the queue)
messages.put(item)
except GeneratorExit:
messages.put(GeneratorExit)


def main():
pass


if __name__ == '__main__':
main()
9 changes: 6 additions & 3 deletions crawler/_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import sys

if sys.getdefaultencoding() != 'utf-8':
reload(sys)
sys.setdefaultencoding('utf-8')
if sys.version_info[0] == 2:
if sys.getdefaultencoding() != 'utf-8':
reload(sys)
sys.setdefaultencoding('utf-8')
else:
pass
Loading