-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Threaded operation #34
base: main
Are you sure you want to change the base?
Changes from all commits
b3349bb
6bcf153
ed7e8c4
2725775
fa06b7f
836f229
19e8a5f
c4e3615
8b46d45
0b6635b
2fe080b
9de70e9
3828390
7b309e7
6b98dfe
b1f8369
4b88669
86c4e5c
5db02d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
from urllib.parse import quote_plus | ||
|
||
__all__ = ('get_notice_type', 'include_notice_types', 'exclude_notice_types', | ||
'archive') | ||
'archive', 'queuehandlerfor') | ||
|
||
|
||
def get_notice_type(root): | ||
|
@@ -85,3 +85,19 @@ def archive(payload, root): | |
with open(filename, 'wb') as f: | ||
f.write(payload) | ||
logging.getLogger('gcn.handlers.archive').info("archived %s", ivorn) | ||
|
||
|
||
def _queuehandler(payload, root, *, queue): | ||
""" Place (payload, root) on queue for threaded operation. | ||
This can be used in the following manner: | ||
gcn.listen(handler=functools.partial(partialize_queue, queue=a_queue)) | ||
""" | ||
queue.put((payload, root)) | ||
|
||
|
||
def queuehandlerfor(queue): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other handlers have function names that are verbs or verb phrases. Please rename this one to be consistent. Perhaps 'enqueue |
||
"""Create a handler that places (payload, root) on the given queue | ||
This can be used in the following manner: | ||
gcn.listen(handler = queuehandlerfor(queue)) | ||
""" | ||
return functools.partial(_queuehandler, queue=queue) |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -28,6 +28,7 @@ classifiers = | |||
Programming Language :: Python :: 3.8 | ||||
Programming Language :: Python :: 3.9 | ||||
Programming Language :: Python :: 3.10 | ||||
Programming Language :: Python :: 3.11 | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a nice addition, but not related to the topic of this PR.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know why GitHub is showing this in the diff. It's already on the main branch, as of #35. Would you please rebase? |
||||
Topic :: Internet | ||||
Topic :: Scientific/Engineering :: Astronomy | ||||
project_urls = | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this. If someone asked how to run the listener in a thread, this isn't how I would suggest to them that they do it. (I would suggest to them that they use an ordinary handler and just launch
gcn.listen
in a thread or a subprocess.)Also, this is missing calls to
queue.task_done()
.